Flowdock
method

create

Importance_2
v2.0.3 - Show latest stable - 0 notes - Class: ActiveResource::Base
create(attributes = {}) public

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

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

The newly created resource is returned. 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.