Jay
Jay

Reputation: 63

How to have viewable profile pages using devise

  1. Users need have their own profile pages

  2. Plus other users need to be able to view anyone else's profile page

  3. I need to be able to link to profile pages in another gem, for example I can click on a post that a user has made (stories gem) and view the poster's profile.

I found a tutorial https://github.com/danweller18/devise/wiki/Allow-Users-to-View-Profile-and-List-All-Users

But this claims to only allow a user to view their own profile. How exactly do I go about to do this (view other's profile)

Upvotes: 0

Views: 193

Answers (2)

Marcos R. Guevara
Marcos R. Guevara

Reputation: 6388

Well,

This is the most common situation, in your routes you need something like this

get user/:user_id/profile

then on your view you can do something like

if current_user.id == params[:user_id]
 # your content when the user is the same
else
 # content for others

Also, you can try to do this on the controller and render different content

Upvotes: 0

lei liu
lei liu

Reputation: 2775

You can view other people's profile, since there is a user's :id params in the route. To link to a user's profile, use:

// using user's name as params
<%= link_to user_path(@user.name) %>

Or

// using user's id as params
<%= link_to user_path(@user) %>

Upvotes: 1

Related Questions