Query string passing in Ruby on Rails -
i want pass id=1 when press link.
**link** **view/index.html.erb** <%=link_to "questions " ,:action=>"index" %>
i want pass id value controller app/post_controller.rb
please tell how access value also.
you can this:
<%= link_to "questions", :action => "index", :id => 1 %>
and more readable version:
<%= link_to "questions", questions_path, id: 1 %>
however, there's propably better way want achieve. if want link question, should this: first retrieve question object in controller this:
@question = question.find(2) # or params[:id]
and in view this:
<%= link_to "question", @question %>
Comments
Post a Comment