Hi there, I''d like to use pretty urls in my web app. I''d also like my methods to look up the relevent table rows using ids. Is there any way of passing on the relevant ids while displaying a pretty url? As far as I can see, I can''t have both. Either I have an ''ugly'' url (companies?project=3) from which I can pluck the relevant object/row with Project.find(params[:project]) or a pretty url (proj1/companies) where to get the row I''d have to use Project.find(:first, conditions => ["short_name =?", params[:project]]). Is there (as Tony Blair or Bill Clinton would say) a third way? Cheers Adam _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Adam Groves wrote:> Hi there, > I''d like to use pretty urls in my web app. I''d also like my methods to look > up the relevent table rows using ids. Is there any way of passing on the > relevant ids while displaying a pretty url? As far as I can see, I can''t > have both. Either I have an ''ugly'' url (companies?project=3) from which I > can pluck the relevant object/row with Project.find(params[:project]) or a > pretty url (proj1/companies) where to get the row I''d have to use > Project.find(:first, conditions => ["short_name =?", params[:project]]). > Is there (as Tony Blair or Bill Clinton would say) a third way?I''ve used the latter technique in a before_filter to set up instance variables for every method they''re needed without having to repeat the code everywhere. Not exactly a ''third way'', but then neither was New Labour. :-) -- Alex
Hello Adam, 2005/10/25, Adam Groves <adam.groves@gmail.com>:> Is there (as Tony Blair or Bill Clinton would say) a third way?Is /projects/edit/1 a bad URL ? That's the default for Rails. Maybe I'm misunderstanding what you want ? projects is your controller (ProjectsController) edit is the method IN the controller (ProjectsController#edit) 1 is the ID of the object (project in this case) you want to act upon (edit) Look in config/routes.rb and the Routing manual at http://manuals.rubyonrails.com/read/book/9 Hope that helps ! François _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails