From f49e449ed5d140b63f30ac046826f81c04e8333d Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Wed, 24 Jan 2007 02:40:32 +0000 Subject: 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 --- activeresource/lib/active_resource/base.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'activeresource/lib/active_resource') 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 resource.valid? will return false, + # while resource.new? will still return true. + # + 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 -- cgit v1.2.3