diff options
author | Rick Olson <technoweenie@gmail.com> | 2007-01-24 02:40:32 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2007-01-24 02:40:32 +0000 |
commit | f49e449ed5d140b63f30ac046826f81c04e8333d (patch) | |
tree | 7821ff304545f96a5cca25e3edff81caea2db3ad /activeresource/lib | |
parent | 0eb8398cfa6d4abf20c85fa59fa1a284dd992172 (diff) | |
download | rails-f49e449ed5d140b63f30ac046826f81c04e8333d.tar.gz rails-f49e449ed5d140b63f30ac046826f81c04e8333d.tar.bz2 rails-f49e449ed5d140b63f30ac046826f81c04e8333d.zip |
Carry over the convenience of #create from ActiveRecord. Closes #7340. [Ryan Daigle]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6025 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/lib')
-rw-r--r-- | activeresource/lib/active_resource/base.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb index f530923224..faf0f046d6 100644 --- a/activeresource/lib/active_resource/base.rb +++ b/activeresource/lib/active_resource/base.rb @@ -70,6 +70,21 @@ module ActiveResource alias_method :set_primary_key, :primary_key= #:nodoc: + # Create a new resource instance and request to the remote service + # that it be saved. This is 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 <tt>resource.valid?</tt> will return <tt>false</tt>, + # while <tt>resource.new?</tt> will still return <tt>true</tt>. + # + def create(attributes = {}, prefix_options = {}) + returning(self.new(attributes, prefix_options)) { |res| res.save } + end + # Core method for finding resources. Used similarly to ActiveRecord's find method. # Person.find(1) # => GET /people/1.xml # StreetAddress.find(1, :person_id => 1) # => GET /people/1/street_addresses/1.xml |