Module: Her::Model::ORM::CreateMethods::ClassMethods

Defined in:
lib/her/model/orm/create_methods.rb

Instance Method Summary collapse

Instance Method Details

#create(params = {}) ⇒ Object

Create a resource and return it

Examples:

@user = User.create({ fullname: "Tobias Fünke" })
# Called via POST "/users/1"


13
14
15
16
17
# File 'lib/her/model/orm/create_methods.rb', line 13

def create(params = {})
  resource = new(params)
  resource.save
  resource
end

#create!(params = {}) ⇒ Object

Raises:



19
20
21
22
23
24
# File 'lib/her/model/orm/create_methods.rb', line 19

def create!(params = {})
  resource = create(params)
  raise RecordInvalid.new(resource.errors) unless resource.errors.empty?

  resource
end