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! While you're at it, check out some resources Treehouse students have shared here.

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


Linking 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
Jason Seifer
Treehouse Guest Teacher

You can link to someone's profile by doing the following:

<%= link_to user.first_name, profile_path(id: user.profile_name) %>

Yes, 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
Jason Seifer
Treehouse Guest Teacher

It 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.

When 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.