Not sure how it works on Rails 3, but I've been using the stringex gem for that for a while now. It has some cool features such as:
rock & roll".to_url => "rock-and-roll" Check it out at http://github.com/rsl/stringex On Tue, Nov 2, 2010 at 8:38 AM, Bodaniel Jeanes <m...@bjeanes.com> wrote: > Matt, > > This has always been easy in rails. All you have to do is define the > `to_param` method on your model. > > E.g. > > class Product < AR::Base > def to_param > "perhaps-product-name-or-other-string" > end > end > > Usually you wouldn't arbitrarily return a string though. I usually have a > column called "permalink" which I initialise on record creation (using > before_create) to be something sensible. Here's a good example: > > class Product < AR::Base > before_create :set_permalink > > def to_param > self.permalink > end > > protected > def set_permalink > self.permalink = self.title.parameterize > end > end > > In order to find the products, you have to also change the controller so > that instead of `Product.find(params[:id])`, you'd do something like ` > Product.find_by_permalink(params[:id])` > > Cheers, > Bo > [image: Bodaniel Jeanes] > > *Bodaniel Jeanes* [image: LinkedIn] > <http://www.linkedin.com/in/bjeanes>[image: > Twitter] <http://twitter.com/bjeanes>[image: Tungle.me] > <http://tungle.me/bjeanes>[image: > Blog] <http://bjeanes.com> > Whttp://bjeanes.com e...@bjeanes.comt+61412639224 > [image: Google Talk] [image: MSN] [image: Google Wave] m...@bjeanes.com > [image: > Skype][image: AIM] bojeanes > > > > > On Tue, Nov 2, 2010 at 7:32 AM, Matthieu Stone > <matthieu.st...@gmail.com>wrote: > >> Hello, >> >> Anyone got any thoughts on the best way to generate search engine friendly >> urls in a rails 3 app? >> >> ie: >> >> www.mysite.com/products/big-green-furry-thing >> >> instead of >> >> www.mysite.com/products/23 >> >> rgds, >> - matt. >> >> >> -- >> 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 rails-ocea...@googlegroups.com. >> To unsubscribe from this group, send email to >> rails-oceania+unsubscr...@googlegroups.com<rails-oceania%2bunsubscr...@googlegroups.com> >> . >> 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 rails-ocea...@googlegroups.com. > To unsubscribe from this group, send email to > rails-oceania+unsubscr...@googlegroups.com<rails-oceania%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/rails-oceania?hl=en. > -- http://awesomebydesign.com -- 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 rails-ocea...@googlegroups.com. To unsubscribe from this group, send email to rails-oceania+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.