Worth a try but it does have wider consequences. For example calling product_path produces
product_url failed to generate from ... It's the kind of thing that I'm looking for though. Perhaps I should just override the default helps generated for the resource? On Mon, Nov 29, 2010 at 12:16 AM, Dmytrii Nagirniak <[email protected]>wrote: > Hi Mark, > > I think you can override to_param method on your Product to return > different URL: > > class Product < ... > def to_param > "#{kind_of_product}/#{id}" > end > end > > Not sure whether it's a good idea to redefine to_param to include slash, > but I guess it should do the job for you. > > You might also want to have a look at permalink_fu or similar. > > Cheers, > Dima. > > On 28 November 2010 23:52, Mark Ratjens <[email protected]> wrote: > >> Suppose I have an ActiveRecord called Product. I can have different kinds >> of products, say "cars", "trucks" and "boats." Because of the nature of the >> app, there is no need to subclass product (i.e, the data and behaviour is >> the same) ... >> >> ... but for SEO reasons I want to be able to generate links in the app >> that include the kind of product, not just "product", for example: >> >> /cars/23 >> /trucks/37 >> /boats/126 >> >> not: >> >> products/23 etc >> >> The thing I am tousling with is generating the appropriate link in the >> app. Is there some way I can adapt: >> >> link_to @product.name, @product >> >> to automagically generate a link with the right product kind ... or do I >> need to do it long-hand, i.e: >> >> link_to @product.name, :controller => @product.kind, :action => :show, >> :id => :product >> >> ? >> >> Thanks in advance >> >> Mark >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby or Rails Oceania" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<rails-oceania%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/rails-oceania?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Ruby or Rails Oceania" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<rails-oceania%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/rails-oceania?hl=en. > -- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.
