#74 10/21 current_userの持続性
本番環境で、シンプルに投稿が出来なくなっている。。
前は出来ていたので、何が変わってしまったかを見る。
開発環境では、出来る時と出来ない時がある。
・昔との変更点を探す
・小川さんのメモでの相違点を探す
・仕組みを再度理解
・current_userにあたりを付ける。
・ログイン後2度目の投稿はだめとか
■eventsが作成され、表示されるまでの流れ
1._events_form.html.erbで入力。
2.それがevents_controllerにparamsとして飛び、createで実行される
3.events/index.html.erbで <%= render 'users/shared/feed' %>として表示される
4.中身は、_event.html.erbに記載
DBにも投稿されていないため、1.2で止まっている。
2.で@event=current_user.event.build...とある。
current_userは!?
---
セッションエラー→名前変更○→検索のやつ○
・削除のやつ
マイページで、削除が出せない
correct_userで、idが使えないからな気がする
application.controller.rbでいじれるか。。
https://qiita.com/you8/items/63ad0b9c07da4323fe26
■ポイント
current_user.id は
user_signed_in? && current_user.id
のように、user_signed_in && とセットで使わないといけない
https://b1840943.hatenablog.jp/entry/2018/05/31/231035
これでも表示されないので、
userの方では、sign_inしていない。(確定)
では、どのように
users/show.html.erbで、user sign_inさせるか。
static_page homeの
@event = current_user.events.build
@feed_items = current_user.feed.paginate(page: params[:page]).search(params[:search])
ってどこに使われてるの?
違う、user_controllerが今回のマイページの箇所
→ここもログイン出来ていない。
user_signed_inがおかしい。
・最初のログインから継続して、ログインさせるか
・その度にログインが継続するような仕組みにするか
・ログインしていないから、current_userがnilになっている
https://teratail.com/questions/67514
■current_userがnilの理由
user_controller.rbで、
def current_user
end
と上書きをしてしまっていたため。