How to add article title to URL using link_to in Rails app? -
i trying follow answer question
how link_to in rails output seo friendly url?
but don't result. in rails 3 app have:
# routes.rb match '/articles/:id/:title' => 'articles#show' resources :articles # articles/index.html.haml - @articles.each |article| = link_to article.title, article, :title => article.title
however, after restarting server, links don't have title: /articles/1, /articles/2
what wrong?
your link_to
using route resources :articles
. if want use custom route you've defined, name route, , use in link_to
:
# routes.rb match '/articles/:id/:title' => 'articles#show', :as => :article_with_title # articles/index.html.erb link_to article.title, article_with_title_path(article, :title => article.title)
also, may want consider looking using friendly_id. you, more transparently.
Comments
Post a Comment