teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

参考にしているサイトを追加

2018/11/05 01:36

投稿

ayachika
ayachika

スコア36

title CHANGED
File without changes
body CHANGED
@@ -272,4 +272,20 @@
272
272
  end
273
273
 
274
274
  end
275
+ ```
276
+
277
+ ちなみに参考にしているサイトは[railsでユーザーと投稿を紐付ける](https://qiita.com/you8/items/63ad0b9c07da4323fe26)です。
278
+ これをもとに、application_controller_rbはこのようになっています。
279
+
280
+ ```
281
+ class ApplicationController < ActionController::Base
282
+ protect_from_forgery with: :exception
283
+ include SessionsHelper
284
+
285
+ before_action :set_current_user
286
+
287
+ def set_current_user
288
+ @current_user = User.find_by(id: session[:user_id])
289
+ end
290
+ end
275
291
  ```