Hi Guys, I have the following route to show the articles for a selected service in my application. http://localhost:3000/services/4/articles I want to be able to have a route to the service name rather than the route such as the following. http://localhost:3000/services/clothes/articles I thought something like the following in the routes.rb file would be the way forward? map.connect ''clothes/'', :controller => ''articles'', :action => "index", :service_id => ''4'' Many thanks in advance Dave -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mon, Dec 8, 2008 at 1:55 PM, Dave Smith <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi Guys, > > I have the following route to show the articles for a selected service > in my application. > > http://localhost:3000/services/4/articles > > I want to be able to have a route to the service name rather than the > route such as the following. > > http://localhost:3000/services/clothes/articlesAssuming that the attribute of the Service is called name, you should define this in your Service model: def to_param name end for more info, look at this post: http://www.jroller.com/obie/entry/seo_optimization_of_urls_in --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Franz Strebel wrote:> On Mon, Dec 8, 2008 at 1:55 PM, Dave Smith > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> http://localhost:3000/services/clothes/articles > > Assuming that the attribute of the Service is called name, > you should define this in your Service model: > > def to_param > name > end > > for more info, look at this post: > > http://www.jroller.com/obie/entry/seo_optimization_of_urls_inI used the following code in the end, as I have a field title in the table. def to_param id.to_s+''-''+title.downcase.gsub('' '', ''-'') end However it puts the address with the ID at the beginning; http://localhost:3000/services/1-horse-&-groom/articles Is there a way I can remove this from the address to tidy it up a bit? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---