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
on 2008-12-08 14:55
on 2008-12-08 15:38
On Mon, Dec 8, 2008 at 1:55 PM, Dave S. <email@example.com> 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...
on 2008-12-08 17:08
Franz S. wrote: > On Mon, Dec 8, 2008 at 1:55 PM, Dave S. > <firstname.lastname@example.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... I 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?