回答編集履歴
1
サンプルコード追加
test
CHANGED
@@ -4,6 +4,36 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
+
以下のような使い方となります
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
|
11
|
+
class HogeController < ApplicationController
|
12
|
+
|
13
|
+
before_action :authenticate_admin!, only: [:show]
|
14
|
+
|
15
|
+
def show
|
16
|
+
|
17
|
+
current_user.id # ログイン中ユーザーのIDを参照
|
18
|
+
|
19
|
+
# 略
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
def index
|
26
|
+
|
27
|
+
current_user&.id # リクエスト時に未ログインなら、 current_user == nil
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
|
7
37
|
詳しくは、github上の[device_token_authのREADME](https://github.com/lynndylanhurley/devise_token_auth)を見るのが一番正確でしょう。
|
8
38
|
|
9
39
|
(`current_user`については、上記READMEの`Methods`の段落に記載があります)
|