method

create

Importance_2
Ruby on Rails latest stable (v7.1.3.2) - 0 notes - Class: ActiveResource::Base
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 => 'myname@nospam.com', :enabled => true)
my_person = Person.find(:first)
my_person.email # => myname@nospam.com

dhh = Person.create(:name => 'David', :email => 'dhh@nospam.com', :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 => 'thatguy@nospam.com', :enabled => true)
that_guy.valid? # => false
that_guy.new?   # => true
Show source
Register or log in to add new notes.