Reputation: 5145
I trying to achieve something like as below :-
<%= link_to "<%= user.email %>", users_path %>
So that each user's email id is to be used as a hyper link to their user profile page.
How to achieve this ? I'm using rails 3.0.1.
Thanks in Advance
Upvotes: 2
Views: 844
Reputation: 19749
Don is close, but users_path is (i presume) the index action of a UsersController, so you don't need (and in fact shouldn't pass) user into the helper.
link_to is actually a helper method, which accepts a few arguments. The first argument is the text of the link itself (what goes in between <a>
and </a>
). You don't need to use the ERB syntax you are trying to use, just pass whatever text you want (user.email, or user.name, whatever).
<%= link_to user.email, user_path(user) %>
Upvotes: 4
Reputation: 366
Try the following, since you want a link to a user and not the index of all users
<%= link_to user.email, user_path(user) %>
Upvotes: 3