0

I want to pass id=1 when i press a link.

**link**
**view/index.html.erb**

<%=link_to "Questions " ,:action=>"index" %>

i want to pass this id value to controller app/post_controller.rb

Please tell how to access that value also.

1 Answer 1

1

You can do it like this:

<%= link_to "Questions", :action => "index", :id => 1 %>

And a more readable version:

<%= link_to "Questions", questions_path, id: 1 %>

However, there's propably a much better way for what you want to achieve. If you want to link to a certain Question, you should do it like this: First you retrieve the question object in your controller like this:

@question = Question.find(2) # or params[:id]

and then in your view you just do this:

<%= link_to "Question", @question %>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.