Forum: Ruby on Rails Using ";action" from ActiveResource client

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (Guest)
on 2007-05-06 12:42
(Received via mailing list)
I have a RESTful Rails (1.2.3) app which implements XML operations. I'm
writing a client side (non-Rails) app to interact with it. The client
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

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
and get the expected result. So my only problem is how to get
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
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
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
and not

Perhaps there is a way to declare a single resource rather than a
in a mapping?

In any case, if I have to change my app to work this way, doesn't that
the ";xxx" member actions superfluous?


753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 candlerb (Guest)
on 2007-05-06 22:33
(Received via mailing list)
OK, I solved the first part of this question. It works if I do
find(:all) not find(1), i.e.

    Unit.find(:all, :from => "/units/1.xml;baz")

It wasn't exactly that simple. The ;baz controller actually returns a
collection of a different object type: <settings><setting>...</
setting></settings>. This confuses ARes, which was expecting
<units><unit>...</unit></units>. So actually what I have to write is

    Setting.find(:all, :from => "/units/1.xml;baz")

But I can cope with that.

I'd still be interested in an answer to the other part of my question
though, which is not to do with ARes but Rails. If I want a RESTful
controller to respond to /things/1/foo[.xml], how do I configure the
routing to do that?

The ARes docs and unit tests imply that this is an expected scenario:

    david = Person.find(:one, :from => "/companies/1/manager.xml")
    assert_equal "David",


753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 candlerb (Guest)
on 2007-05-07 21:00
(Received via mailing list)
FYI, after digging around in subversion, it seems that in Edge Rails
the format of REST URLs has changed, from /foo/1.xml;action to /foo/1/

Also, this new format is supported by ActiveResource in lib/
active_resource/custom_methods.rb, so you can issue queries like

    settings = => '1').get(:baz)

(although in this case I get back a straight array of hashes, not
Setting objects). So now I need to decide whether to live life on The
Edge :-)
This topic is locked and can not be replied to.