On 26-Jan-07, at 10:37 AM, Ed Hickey wrote:I'm in the process of converting a project to be RESTful (Rails 1.2.1) but am running into an issue I can't quite solve (gracefully).
I have a list of Accounts that all need to be modified in the same way ('paused') Using the restful routes, I can easily setup a route for pausing one:
map.resources :accounts, :member => { :pause => :put }
Though, I'm not sure how to setup a route to for multiple deletions. This is the only solution I've found, though it breaks a few REST conventions:
map.pause_accounts '/accounts;pause', :controller => "accounts", :action => "pause"
I can't figure out how to force the named route to use the PUT method, plus I have to hack my 'pause' action to accept both a single Account id (params[:id]) as well as multiple ids. I'm sure I'm missing something simple. I can't seem to find much helpful documentation or examples.
Anyone?Ed, reading your requirement leads me to think that you are missing a Model.The Accounts likely are connected in your domain a belongs_to relationship.
Although I don't know more, having such a requirement would be an indication to me that I've not modeled something important.
And having such a relationship would allow you to track the transactional info that happens through such a group REST action.
If you would like more info on refactoring to REST, check out this
article by Scotty Raymond (IconBuffet, Blinksale, etc). It is
available on his site, but I have found this link to be more reliable
(doh!):
http://www.touset.org/blog/archives/category/technical/rails/
One of the things to note is how REST takes a different way of thinking
about your app. Where before you may have had a login action on some
account controller, now you might want an object to represent what a
login does. A login creates a session, so why not have a RESTful
sessions controller? That is what Scotty has done here. Most of the
time, if you are struggling with custom actions, it is because there is
some other way to represent the relationship than what you had before.
Just think in terms of "what am I creating here?"
Hope this helps,
Chris Beck
redmotive