diff options
author | Rasik Pandey <rbpandey@gmail.com> | 2008-08-30 04:19:18 +0300 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-08-29 18:45:39 -0700 |
commit | 16b9a554db7e1bf3f5f224cdc5b4d27480e053ff (patch) | |
tree | 7eef718fa623a5fcebb90de534b0eba2a6eae020 /activeresource/lib/active_resource/custom_methods.rb | |
parent | 11eb29f60ab79caf22f7ca715500e32d9a1b03a2 (diff) | |
download | rails-16b9a554db7e1bf3f5f224cdc5b4d27480e053ff.tar.gz rails-16b9a554db7e1bf3f5f224cdc5b4d27480e053ff.tar.bz2 rails-16b9a554db7e1bf3f5f224cdc5b4d27480e053ff.zip |
Format related patches to support serializing data out in the correct format with correct http request headers per http method type [#450 state:resolved]
Signed-off-by: Tarmo Tänav <tarmo@itech.ee>
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activeresource/lib/active_resource/custom_methods.rb')
-rw-r--r-- | activeresource/lib/active_resource/custom_methods.rb | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/activeresource/lib/active_resource/custom_methods.rb b/activeresource/lib/active_resource/custom_methods.rb index 770116ceb7..b6fffc4da2 100644 --- a/activeresource/lib/active_resource/custom_methods.rb +++ b/activeresource/lib/active_resource/custom_methods.rb @@ -30,7 +30,7 @@ module ActiveResource # Person.get(:active) # GET /people/active.xml # # => [{:id => 1, :name => 'Ryan'}, {:id => 2, :name => 'Joe'}] # - module CustomMethods + module CustomMethods def self.included(base) base.class_eval do extend ActiveResource::CustomMethods::ClassMethods @@ -83,24 +83,25 @@ module ActiveResource "#{prefix(prefix_options)}#{collection_name}/#{method_name}.#{format.extension}#{query_string(query_options)}" end end - + module InstanceMethods def get(method_name, options = {}) connection.get(custom_method_element_url(method_name, options), self.class.headers) end - - def post(method_name, options = {}, body = '') + + def post(method_name, options = {}, body = nil) + request_body = body.nil? ? encode : body if new? - connection.post(custom_method_new_element_url(method_name, options), (body.nil? ? to_xml : body), self.class.headers) + connection.post(custom_method_new_element_url(method_name, options), request_body, self.class.headers) else - connection.post(custom_method_element_url(method_name, options), body, self.class.headers) + connection.post(custom_method_element_url(method_name, options), request_body, self.class.headers) end end - + def put(method_name, options = {}, body = '') connection.put(custom_method_element_url(method_name, options), body, self.class.headers) end - + def delete(method_name, options = {}) connection.delete(custom_method_element_url(method_name, options), self.class.headers) end @@ -110,7 +111,7 @@ module ActiveResource def custom_method_element_url(method_name, options = {}) "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}.#{self.class.format.extension}#{self.class.send!(:query_string, options)}" end - + def custom_method_new_element_url(method_name, options = {}) "#{self.class.prefix(prefix_options)}#{self.class.collection_name}/new/#{method_name}.#{self.class.format.extension}#{self.class.send!(:query_string, options)}" end |