method

get

Importance_1
v2.1.0 - Show latest stable - 1 note - Class: ActiveResource::Connection
get(path, headers = {}) public

Execute a GET request. Used to get (find) resources.

Show source
Register or log in to add new notes.
January 5, 2011
0 thanks

Passing in parameters

If you want to pass in parameters you can do it like this:

User.get(:find_by_name, headers = {:name => "bob"})
=> /users/find_by_name.xml?name=bob

For nested routes…

routes.rb

resources :companies do
  resources :users do
    member do
      get :find_by_name
    end
  end
end

In your api code…

class User < ActiveResource::Base  

  self.site = "/companies/:company_id"

  def self.find_by_name(name, company_id)
    User.get(:find_by_name, headers = {:name => name, :company_id => company_id}
  end
end

Then doing…

User.find_by_name("bob", 1)

Would call

companies/1/users/find_by_name.xml?name="bob"

This works in Rails 3.1 - not sure about older versions (specifically I think the routes were done differently in < 3