dora
dora

Reputation: 1344

Ruby on Rails Custom link_to

I have a list posts, which when clicked on should show the url as posts/this+is+the+title. After doing this, how would I catch this in the controller to fetch data from the database?

     <% @posts.each do |fq| %>
     <%= link_to fq.title,fq%>
     <p><%= fq.content %></p>
     <hr />
     <% end %>

Assuming a title is "Ruby on Rails" with id =3 The above code, generates a url like this 'localhost:3000/posts/3'. But I would want the link to be 'localhost:3000/posts/ruby+on+rails'

Upvotes: 0

Views: 227

Answers (1)

Manoj Monga
Manoj Monga

Reputation: 3083

You are looking for pretty urls those includes some text instead of ids as rails generates. Then you must look into friendly_id gem. There is good screen cast you would be interested in.

Upvotes: 0

Related Questions