method

create

create(attributes = {})
public

Creates a new resource instance and makes a request to the remote service that it be saved, making it equivalent to the following simultaneous calls:

  ryan = Person.new(:first => 'ryan')
  ryan.save

Returns the newly created resource. If a failure has occurred an exception will be raised (see save). If the resource is invalid and has not been saved then valid? will return false, while new? will still return true.

Examples

  Person.create(:name => 'Jeremy', :email => '[email protected]', :enabled => true)
  my_person = Person.find(:first)
  my_person.email # => [email protected]

  dhh = Person.create(:name => 'David', :email => '[email protected]', :enabled => true)
  dhh.valid? # => true
  dhh.new?   # => false

  # We'll assume that there's a validation that requires the name attribute
  that_guy = Person.create(:name => '', :email => '[email protected]', :enabled => true)
  that_guy.valid? # => false
  that_guy.new?   # => true