ruby on rails - Creating seo friendly url from a string -
hey guys i'm trying create url friendly link string. instead of example.com/jessica alba, want example.com/jessica-alba
how link_to tags link me seo friendly permalink?
i need make sure show method displays seo friendly permalink in address bar , accepts seo friendly permalink.
you can override to_param method in model.
so if have model called celebrity, has name column can go:
class celebrity < activerecord::base def to_param self.name.downcase.gsub(' ', '-') end end then:
jessica_alba = celebrity.find_by_name("jessica alba") link_to "jessica alba", celebrity_path(jessica_alba)
Comments
Post a Comment