Q&A
前提
deviseを使用しています。
aboutページへ遷移したいのですが、上のURLはhomes/aboutなのにログインページが表示されてしまいます。下の写真の確認をお願いします。
実現したいこと
about画面を表示したい
発生している問題・エラーメッセージ
ターミナルを見たところ一瞬だけhomes/aboutへ飛ぼうとしてますがすぐにsign inに行ってしまいます
Started GET "/homes/about" for 210.1.146.36 at 2022-08-09 10:16:31 +0000 Cannot render console from 210.1.146.36! Allowed networks: 127.0.0.0/127.255.255.255, ::1 Processing by HomesController#about as HTML Completed 401 Unauthorized in 1ms (Allocations: 226) Started GET "/users/sign_in" for 210.1.146.36 at 2022-08-09 10:16:31 +0000 Cannot render console from 210.1.146.36! Allowed networks: 127.0.0.0/127.255.255.255, ::1 Processing by Devise::SessionsController#new as HTML Rendering layout layouts/application.html.erb Rendering devise/sessions/new.html.erb within layouts/application Rendered devise/shared/_links.html.erb (Duration: 0.3ms | Allocations: 164) Rendered devise/sessions/new.html.erb within layouts/application (Duration: 2.9ms | Allocations: 1306) [Webpacker] Everything's up-to-date. Nothing to do Rendered layout layouts/application.html.erb (Duration: 7.3ms | Allocations: 3248) Completed 200 OK in 9ms (Views: 8.4ms | Allocations: 3852)
該当のソースコード
application.html.erb
1 <% if user_signed_in? %> 2 <li> 3 <%= link_to user_path(current_user),class: "nav-link text-light" do %> 4 <i class="fas fa-home"></i> Home 5 <% end %> 6 </li> 7 <li> 8 <%= link_to users_path, class: "nav-link text-light" do %> 9 <i class="fas fa-user"></i> Users 10 <% end %> 11 </li> 12 <li> 13 <%= link_to books_path, class: "nav-link text-light" do %> 14 <i class="fas fa-book-open"></i> Books 15 <% end %> 16 </li> 17 <li> 18 <%= link_to destroy_user_session_path, method: :delete, class: "nav-link text-light" do %> 19 <i class="fas fa-sign-out-alt"></i> Log out 20 <% end %>r 21 </li> 22 <% else %> 23 <li> 24 <%= link_to root_path, class: "nav-link text-light" do %> 25 <i class="fas fa-home"></i> Home 26 <% end %> 27 </li> 28 <li> 29 <%= link_to about_path, class: "nav-link text-light" do %> 30 <i class="fas fa-link"></i> About 31 <% end %> 32 </li> 33 <li> 34 <%= link_to new_user_registration_path, class: "nav-link text-light" do %> 35 <i class="fas fa-user-plus"></i> Sign up 36 <% end %> 37 </li> 38 <li> 39 <%= link_to user_session_path, class: "nav-link text-light" do %> 40 <i class="fas fa-sign-in-alt"></i> Log in 41 <% end %>
controllerも載せておきます
class ApplicationController < ActionController::Base before_action :authenticate_user!, except: [:top] before_action :configure_permitted_parameters, if: :devise_controller? def after_sign_in_path_for(resource) user_path(current_user) end def after_sign_out_path_for(resource) root_path end def after_sign_up_path_for(resource) user_path(current_user) end protected def configure_permitted_parameters added_attrs = [:user_name, :email, :password, :password_confirmation, :remember_me] devise_parameter_sanitizer.permit :sign_up, keys: added_attrs devise_parameter_sanitizer.permit :account_update, keys: added_attrs end end
routes.rb
1Rails.application.routes.draw do 2 devise_for :users 3 root to: 'homes#top' 4 get "/homes/about" => "homes#about", as: "about" 5 resources :books, only: [:create, :index, :show, :edit, :update, :destroy] 6 resources :users, only: [:index, :show, :edit, :update] 7 # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html 8end
初めに行った通りURLだけはhomes/aboutへ遷移しています
画面だけsign_inになります
試したこと
rails routesにてpathの再確認
routes
1 root GET / homes#top 2 about GET /homes/about(.:format) homes#about
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。