Mo.
Mo.

Reputation: 42583

Rails 3: Adding a params value to a link_to call?

I have built a very simple internal messaging system inside my application, i want to add a link to each user profile page where the logged in user can click on the link to send the other user which profile they are viewing a message.

messages is nested under users, so new message page would be /users/1/messages/new

so i have: <%= link_to 'Send Message', new_user_message_path(current_user) %> how can i add a params values to the link with the user id and name of of the user he/she is viewing (object is called @user) so the href would look something like this: /users/1/messages/new?to_id=3&to_name=somename

Thanks

Upvotes: 1

Views: 758

Answers (1)

fl00r
fl00r

Reputation: 83680

<%= link_to 'Send Message', new_user_message_path(current_user, :to_id => 3) %>

Upvotes: 4

Related Questions