ptontiger
2007-Nov-15 23:32 UTC
RESTful rails customized resource mapping concerning edit action and monolithic template
Hi everyone, this is my first post. I''m reorganizing a rails app to use RESTful routes. I have a users controller that''s mapped RESTfully. Before the switch to REST I had three separate actions to display a form to edit (on GET) and update (on POST) personal info, email address, and password. While I''ve managed to safely consolidate the update code for the three actions into a single RESTful update action, I''m wondering what''s the easiest way to do the following: /users/1/edit/email /users/1/edit/password /users/1/edit/personal I know that I could add this in routes.rb: map.connect ''users/:id/edit/:what'', :controller => ''users'', :action => ''edit'' and handle which template is rendered in the controller like so: def edit if params[:what] == ''email'' # Render email template elsif params[:what] == ''password'' # Render password template elsif params[:what] == ''personal'' # Render personal template else # Render generic edit template end end But let''s say for some completely arbitrary reason I want actions in the users controller named email password and personal that respond to the above routes. Is there any way to incorporate this mapping within map.resources? I tried something like: map.resources :articles, :new => {:preview => :post} but with :edit... map.resources :users, :edit {:email => :get, :password => :get, :personal => :get} and it doesn''t work. I can understand why the former works and the latter doesn''t but was wondering if it is in fact possible to configure the desired route within map.resources. Or do you think the present solution is sufficient (in that it is good/adequate practice)? Generally speaking, how would you go about coding a RESTful controller where a monolithic edit action (or more precisely template) doesn''t fit the bill? Thanks for all of your help. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---