I have a RESTful Rails (1.2.3) app which implements XML operations. I’m
now
writing a client side (non-Rails) app to interact with it. The client
side
has activeresource and activesupport, both taken from SVN trunk.
I have basic ActiveResource REST fetches working OK:
unit = Unit.find(1) # GET /units/1.xml
unit = Unit.find(:all, :params => { :foo => "bar" }) # GET
/units.xml?foo=bar
Now, my problem is how to invoke named controller actions such as ;baz
unit = Unit.find(1, ??WHAT GOES HERE??) # GET /units/1.xml;baz
On the Rails server side, the corresponding route is
map.resources :units, :member => {
:baz => :get,
}
and this part is working fine, e.g. I can point a browser to
http://localhost:8000/units/1.xml;baz
and get the expected result. So my only problem is how to get
ActiveResource
to issue this query in the first place.
I have tried
Unit.find(1, :from => "/units/1.xml;baz")
but tcpdump shows that it is only sending “GET /units/1.xml”.
So any ideas how to do this?
Alternatively: I could change my Rails application to accept
/units/1/baz.xml as the request format. I think this ought to be
possible,
as implied by the following example in the ActiveResource source code:
# Person.find(:one, :from => "/companies/1/manager.xml") # =>
GET /companies/1/manager.xml
However, how would I configure routing in the Rails app to accept a
request
in this format? At the moment, a request to /units/1/baz gives a 404.
I have the Agile book v2, and it shows how to do nested routes, but IIUC
that would be
/companies/1/managers
/companies/1/managers/1
and not
/companies/1/manager
Perhaps there is a way to declare a single resource rather than a
collection
in a mapping?
In any case, if I have to change my app to work this way, doesn’t that
make
the “;xxx” member actions superfluous?
Thanks,
Brian.