开发者

Rails Devise User help

开发者 https://www.devze.com 2023-04-09 19:54 出处:网络
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.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号