0

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'

dora
  • 1,314
  • 2
  • 22
  • 38
  • First thing first: your problem isn't clear enough to us. If you could specify a use case, or show some code, and tell us what you're trying to achieve and where you are currently toward this goal. Now. You seem to have troubles with understanding rails routing : I'd suggest reading [this guide](http://guides.rubyonrails.org/routing.html), which is the reference on the matter. – ksol Feb 15 '13 at 09:00

1 Answers1

0

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.

Manoj Monga
  • 3,033
  • 14
  • 19