ルーティング先が意図したところに行かない。
railsを勉強し始めた初心者です。
deviseの認証機能を実装しています。
基本的なログイン・ログアウト機能やユーザーネームを加えるなどといったところまでなんとか自力で実装することができました。
しかし、deviseのルーティングについて分からないことがあり、ログアウト後にappication.html.erbに遷移してもらいたのにも関わらず、ログインページに遷移してしまいます。
ログインするとapplication.html.erbのページに飛んでくれるのですがなぜログアウトするとどうしてもログインページに飛んでしまいます。
私になりに色々と試してみたのですがどうしても解決する事が出来ませんでしたので、教えて頂けると嬉しいです。
ruby
1//routes.rb 2Rails.application.routes.draw do 3 4 root 'home#top' 5 devise_for :users 6 7 get "users/index" => "users#index" 8 get "users/:id" => "users#show" 9 10 #get "/" => "home#top" 11 get "about" => "home#about" 12 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 13end
html
1<!-- apprication.html.erb --> 2<!DOCTYPE html> 3<html> 4 <head> 5 <title>WorkoutApp</title> 6 <%= csrf_meta_tags %> 7 8 <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 9 <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> 10 </head> 11 12 <body> 13 <header> 14 <div class="header-logo"> 15 <%= link_to("Dope", "/") %> 16 </div> 17 <ul class="header-menus"> 18 <% if current_user %> 19 <li> 20 <%= current_user.name + " さん"%> 21 </li> 22 <li> 23 <%= link_to("トレーナーを探す", "/users/index") %> 24 </li> 25 <li> 26 <%= link_to 'ログアウト', destroy_user_session_path, method: :delete %> 27 </li> 28 <% else %> 29 <li> 30 <%= link_to 'トレーナーになる', new_user_registration_path %> 31 </li> 32 <li> 33 <%= link_to("Dopeとは", "/about") %> 34 </li> 35 <li> 36 <%= link_to("トレーナーを探す", "/users/index") %> 37 </li> 38 <li> 39 <%= link_to '新規登録', new_user_registration_path %> 40 </li> 41 <li> 42 <%= link_to 'ログイン', new_user_session_path %> 43 </li> 44 <% end %> 45 </ul> 46 </header> 47 48 <% if flash[:notice] %> 49 <div class="flash"> 50 <%= flash[:notice] %> 51 </div> 52 <% end %> 53 <!-- 54 <% if @current_user %> 55 <%= link_to(@current_user.name, "/users/#{@current_user.id}") %> 56 <% end %> 57 <%= render 'layouts/alerts' %> 58 --> 59 60 <%= yield %> 61 </body> 62</html>
ruby
1//application_controller.rb 2class ApplicationController < ActionController::Base 3 protect_from_forgery with: :exception 4 before_action :authenticate_user! 5 before_action :configure_permitted_parameters, if: :devise_controller? 6 7 protected 8 def configure_permitted_parameters 9 devise_parameter_sanitizer.permit(:sign_up, keys: [:name, :image]) 10 devise_parameter_sanitizer.permit(:account_update, keys: [:name]) 11 end 12end 13
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/11/22 03:42