Messages with rails activeresource
I have a quick question about the active resource. If I have a user resource when I call like
User.find(1).put(:promote, :position => 'manager')
According to the api it translates this call / users / 1 / promote.xml? Position = manager
My question is that. Does activeresource actually make two calls here? find the get execution then cast on that object or add app.put to .find means it just makes one call. If so, then the only reason for .find is to specify the correct URL format for / users /: id / promotion ??
I couldn't find in the docs where this could be stated, but it's .find, which makes me think maybe there are two service calls happening?
a source to share
If ActiveResource works like ActiveRecord, I would say yes. If you do something like
Foo.find(1).update_attributes(:name=>"Bar")
ActiveRecord first performs a selection to retrieve the object and then issues an update call to the database to update the record. I would suggest that ActiveResources functions in a similar way where it makes two web service calls to get the object and then updates the object.
a source to share
Put the following words in your inners:
class ActiveResource::Connection
# Creates new Net::HTTP instance for communication with
# remote service and resources.
def http
http = Net::HTTP.new(@site.host, @site.port)
http.use_ssl = @site.is_a?(URI::HTTPS)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl
http.read_timeout = @timeout if @timeout
#Here the addition that allows you to see the output
http.set_debug_output $stderr
return http
end
end
Search for "http.set_debug_output $ stderr" "ActiveResource" to find the original author of this helpful tip.
a source to share