On 29 November 2010 16:10, Korny Sietsma <[email protected]> wrote: > If you want to both match "/cars/123" and also match /foo/bar" where "foo" > isn't a product type... then you have a big problem just waiting to happen, > imho. > > Not necessarily. I think that the solution of Bayan Khalili will work pretty well here.
Assuming that `Product.dynamically_generated_list_of_available_types` returns ['cars', 'boats']. Then the URLs "/cars/123" and "/boats/123" will match correctly the "products#show" route. While "/foo/bar/" will not, but will possibly match an other route. It should only be defined AFTER the "products#show" route. So far it looks like a pretty good solution. Cheers, Dima. - Korny > > On Mon, Nov 29, 2010 at 1:57 PM, Pat Allan <[email protected]>wrote: > >> I think the issue would more be the routing with the rest of the app - >> '/:type/:id' would match a good number of paths you wouldn't actually want >> it to. >> >> I think Andy's got it spot on before - you do indeed use that route, but >> it becomes your catch-all, at the end of your routes file. >> >> There's still issues with being able to generate the paths neatly, but a >> helper method or two should take care of that. The following may even work: >> >> def link_to(*args, &block) >> if args[1] && args[1].is_a?(Product) >> # build your product path here >> else >> super >> end >> end >> >> Could definitely be cleaner, but that's what I'd start with. >> >> -- >> Pat >> >> On 29/11/2010, at 1:51 PM, Ben Hoskings wrote: >> >> > How about just: >> > >> > match '/:type/:id' => 'products#show' >> > >> > And then in ProductsController#show, use params[:id] and params[:type] ? >> > >> > Ben >> > >> > On 29 November 2010 09:44, Mark Ratjens <[email protected]> wrote: >> > The requirement is to have urls of the form >> > >> > /cars/23 >> > >> > not >> > >> > /products/cars-23 >> > >> > This will, of course, be my fall-back position if I can't get exactly >> what is wanted. >> > >> > Also, I'm already using friendly_id ... my id's aren't actually numeric, >> but it doesn't change the problem. I've read though the friendly_id doco ... >> it doesn't seem to help with adapting the url beyond id's and nested id's. I >> have read at least one post where Norman Clark has answered saying that >> friendly_id is not aimed at solving routing issues. >> > >> > >> > On Mon, Nov 29, 2010 at 9:35 AM, Andy Shen <[email protected]> wrote: >> > You could consider mapping the following route to products controller >> > >> > /products/:type/:id >> > >> > or have a look into friendly_id, which is along the same concept of >> > to_params, maybe use id like car-23, truck-37, boat-126 >> > >> > 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]<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]<rails-oceania%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/rails-oceania?hl=en. >> >> > > > -- > Kornelis Sietsma korny at my surname dot com http://korny.info > "Every jumbled pile of person has a thinking part > that wonders what the part that isn't thinking > isn't thinking of" > > -- > 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.
