method
create
v3.0.0 -
Show latest stable
-
0 notes -
Class: ActiveResource::Base
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3 (0)
- 2.1.0 (-1)
- 2.2.1 (1)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (-2)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
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