Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Andrew Heil
1,836 PointsLinking to profiles - simple ruby on rails application
We need to add a link to show the users profile. Would we use params[:id] or would we use the user name?
or would we redirect paramsid to the username in the path statement
2 Answers

Jason Seifer
Treehouse Guest TeacherYou can link to someone's profile by doing the following:
<%= link_to user.first_name, profile_path(id: user.profile_name) %>

Richard English
14,012 PointsWhen I try this I get undefined local variable or method `user' for #<#<Class:0x00000100e4a060>:0x00000102bba5c8>
I am able to use <li><%= link_to current_user.first_name, current_user.profile_name %></li>
but this causes issues when used on certain pages.
Thanks!
Jordan Hosmer
3,112 PointsJordan Hosmer
3,112 PointsYes, I am having a similar problem. I tried your suggestion, but also <%= link_to current_user.first_name, profile_path(id: user.profile_name) %>
Any explanation why I am receiving an error - undefined local variable or method `user' for #<#<Class:0x00000100d44af8>:0x00000103fe4670>
Jason Seifer
Treehouse Guest TeacherJason Seifer
Treehouse Guest TeacherIt depends on where you link to it. In the example above, I'm assuming that users are being linked to inside of the @users.each do |user| block. That way you have access to the user. In other areas, you may have a different variable name.