bjoern
bjoern

Reputation: 1019

Creating user profile pages Rails 3 app

I'm working on a site where every user has a profile that everyone else can see.

i.e.

http://localhost:3000/trista

Right now i stupidly pull in all the data in the view using current_user.name etc.

Sorry, this is probably really simple but how do I add the user info for "trista" and not me, the current_user?

Thanks for your help!

Upvotes: 1

Views: 163

Answers (1)

MurifoX
MurifoX

Reputation: 15089

Well, it seems that you have a User model. And the action you are requesting is the show on on your users_controller.
This way i believe you have something similar to this:

def show
  @user = User.find_by_name(params[:name]) # This option
  @user = User.find_by_name(params[:id])   # Or this option

The thing is, you load the @user instance variable so you can use it in your views like this:

<%= @user.name %>

Using current_user will get the logged one. Using @user, you can populate it anyway you want in your controller. Hope it gives you some enlightment.

Upvotes: 2

Related Questions