Rails Devise User help
In devise how would I, I am not sure how to phrase it, return a user. I am able to use开发者_JAVA百科r_signed_in? but what about user. I want to check in show if @user is the same one as the user that is currently signed in.
Devise has methods like current_user
which returns the "user" that is logged in.
Also, depending on your "User" model the helper methods will be adjust accordingly. So if you have an Admin
class that is your devise model, you can use something like current_admin
, and so on.
Devise has a current_user
helper that's available.
You could do this:
def show
@user = User.find(params[:id])
if @user == current_user
# something
end
end
But maybe you just want to do this?
class UsersController < ApplicationController
before_filter :authenticate_user!
def show
@user = User.find(params[:id])
end
end
精彩评论