17
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails devise ログイン中のユーザー情報の取得 

Last updated at Posted at 2019-03-16

# deviseを使った時に、ログイン中のユーザー情報を取得する方法

使用するコントローラ内にて、
before_action :authenticate_user!
とすると、current_userでユーザー情報を取得できます。

ログイン中のユーザーIDであれば、以下のようにすれば取得可能です。

XXX_controller.rb
class XXXController < ApplicationController
before_action :authenticate_user!

  def index
  end

  def new
    @user = current_user.id
  end

end

#参考
https://github.com/plataformatec/devise#controller-filters-and-helpers

時間のあるときに一度しっかり読んだほうが良いと感じました。

17
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?