deviseを利用して、application.html.erb
のヘッダーメニューにloginしている場合と、していない場合のメニューを作りました。
サイト自体のトップページを表示させたときはuser_signed_in?
がしっかりと動いているので、メニューがサインイン時の表示になっていますが、showなどの、TOP以外のページへ移動したときは、サインインしていない時のメニューが表示されてしまいます。
ruby
1<% if user_signed_in? %> 2<ul class="nav navbar-nav navbar-right"> 3 <li><span class="navbar-text">ようこそ <strong><%= link_to current_user.name, current_user, { :class => "navbar-link"} %></strong> さん</span></li> 4 <li><%= button_to 'ログアウト', destroy_user_session_path, method: :delete, :class => "btn btn-default navbar-btn" %></li> 5</ul> 6<% else %> 7<ul class="nav navbar-nav navbar-right"> 8 <li><%= button_to 'サインアップ', new_user_registration_path, method: :get, :class => "btn btn-default navbar-btn" %></li> 9 <li><%= button_to 'ログイン', new_user_session_path, method: :get, :class => "btn btn-default navbar-btn" %></li> 10</ul> 11<% end %>
ruby
1class ApplicationController < ActionController::Base 2 # Prevent CSRF attacks by raising an exception. 3 # For APIs, you may want to use :null_session instead. 4 protect_from_forgery with: :exception 5 6 before_action :configure_permitted_parameters, if: :devise_controller? 7 8 def configure_permitted_parameters 9 devise_parameter_sanitizer.for(:sign_up) << :name 10 end 11 #deviseでのサインイン後のリダイレクト先 12 def after_sign_in_path_for(resource) 13 root_path 14 end 15end
どのような原因が考えられるのでしょうか?
ご教授お願いします。
正常に動作しそうな気がします。
Railsやブラウザのキャッシュの可能性は無いでしょうか?
解決しました。ありがとうございます。
回答1件
あなたの回答
tips
プレビュー