/posts/1/
will be converted to /posts/1-article-name/
gem install rails -v=3.1.3
in the consolerails new nice_urls
. As a result, we have a new clean project with all the installed jams, due to the fact that at the end of the project generation a bundler was automatically launched.rails g scaffold Post title:string text:text
rake db:migrate
. Now you can start the server ( rails s
command) and look at what we currently have at localhost:3000/posts
app/views/posts/index.html.erb
and find the line that forms the link to the show
:<%= link_to 'Show', post %>
post
is an object that is used when forming the path. It should be replaced with this design:post_path(:id => "#{post.id}-#{post.title.parameterize}")
show
action, you need to add at least one article, which will be given a title. Let's use the interface to create posts and call it “The test of nice urls”. After creating posts in the listing, the link should no longer lead to /posts/1
, but to /posts/1-the-test-of-nice-urls
Source: https://habr.com/ru/post/133627/
All Articles