0

I have a static page that has several links. These links route to the pro_show action in my Posts controller.

 def pro_show
   @posts = Post.where(:code => @code)
 end

I want to pass in the value of :code through my routes. :code is a string.
Right now my routes look like the below route. How do I assign a string value to @code ? I DO NOT need to change the :code of any Post. I need to use the @code variable to sort my Post records as you can see in my action.

This is what I am doing right now=>

<td><%= link_to "This Post", pro_show_path(@code => 87889) %></td>

Am I doing this correctly? Does the value of @code need to be in quotes? Thanks

hey
  • 55
  • 3
  • possible duplicate of [pass parameter by link\_to ruby on rails](http://stackoverflow.com/questions/1898737/pass-parameter-by-link-to-ruby-on-rails) – Vucko Sep 24 '15 at 13:47

1 Answers1

1

The below should work

<td><%= link_to "This Post", pro_show_path(:code => 87889) %></td>

And in the controller

def pro_show
  @posts = Post.where(:code => params[:code])
end
Pavan
  • 33,316
  • 7
  • 50
  • 76