Reputation: 970
I would like to redirect to the appropriate resource user when user wants to go to his profile.
Like this:
get 'profile', to: redirect("/users/#{ current_user.id }")
I don't know if it's possible
Upvotes: 0
Views: 63
Reputation: 1807
OK, after confirming your intention, since you have already had a users controller, and you have already implemented "users#show" which makes it possible for users to view other user's profile. I guess you can do it like this:
get '/profile', to:"users#profile"
a) not redirect, just render the show action with required variables
def profile
@user = current_user
render :action => "show" # if your show function is only depends on @user variable
end
b) redirect
def profile
redirect_to action: "show", id: current_user.id
end
Upvotes: 1
Reputation: 1371
Redirecting user to an URL like /users/#{ current_user.id }
for their profile page is not recommended. It could be an IDOR if you don't have user authorization in that endpoint(i.e, checking if the user id in the URL is for current user only)
Having said this, you can try @abhishek's answer to handle show action
Upvotes: 1
Reputation: 1482
Make your routes
match 'profile' => 'users#show', :via => :get
in your show action
@user = current_user
this will help to create the profile page of the user
Upvotes: 1