Ruby on RailsチュートリアルでRubyとRailsを学んでいるものです。
1日かけても問題が解決できず、ご相談させていただきました。
前提・実現したいこと
Post通信を成功させ、ログインできるようにしたい。
※ログイン画面は表示されますが、ログイン後の画面が表示されません。
発生している問題・エラーメッセージ
現在、10章の「ユーザー更新」まで作業が進んでいる状態なのですが、
動作確認のためのいっかんとして、ログインをしたところ、
「画面のローディングが終わらず、遷移しない」
といった現象が起きており、困ってます。。。
※9章までが終わる時点ではログインができていました。
※9章完了から10章開始まで、1週間ほど間が空いてます。
エラーHTMLに遷移せず、
Railsのエラーログを確認しましたが、
特にExceptionなどは発見できませんでした。
該当のソースコード
ログイン時のコントローラ
#ログイン時のコントローラー : sessions_controller.rb class SessionsController < ApplicationController #getリクエスト送信時のアクション def new #ログイン画面を表示するだけのアクション logger.debug("ログイン画面へ遷移しました。") end #postリクエスト送信時のアクション def create #問題のアクション #動作確認のためにログを出力していますが、このログも吐かれていませんでした。 logger.debug("ログインのサブミットボタンが謳歌されました。") user = User.find_by(email: params[:session][:email].downcase) if user && user.authenticate(params[:session][:password]) logger.debug("ユーザーがあるのでログインしました。") #ユーザーログイン後にユーザー情報のページにリダイレクトする log_in user params[:session][:remember_me] == '1' ? remember(user) : forget(user) redirect_to user else logger.debug("ユーザーがありませんでした。") #エラーメッセージを作成する flash.now[:danger] = 'Invalid email/password combination' render 'new' end end #deleteリクエスト送信時のアクション def destroy log_out if logged_in? redirect_to root_url end end
ログイン画面のHTML
<% provide(:title , "Log in")%> <h1>Log in</h1> <div class="row"> <div class="col-md-6 col-md-offset-3"> <%= form_for(:session, url: login_path) do |f| %> <%= f.label :email%> <%= f.email_field :email,class: 'form-control'%> <%= f.label :password %> <%= f.password_field :password,class:'form-control'%> <%= f.label :remember_me , class: "checkbox inline" do %> <%= f.check_box :remember_me %> <span>Remember me on this computer</span> <% end %> <%= f.submit "Log in",class: "btn btn-primary"%> <% end %> <p>New user? <%= link_to "Sign up now!" , signup_path %></p> </div> </div>
#ルートファイル : routes.rb Rails.application.routes.draw do get 'sessions/new' #get 'users/new' get "/signup",to: "users#new" # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root "static_pages#home" #get 'static_pages/help' get 'help' ,to: "static_pages#help" #get 'static_pages/about' get 'about',to: 'static_pages#about' #get 'static_pages/contact' get 'contact',to: 'static_pages#contact' get '/login',to: 'sessions#new' post '/login',to: 'sessions#create' delete '/logout',to: 'sessions#destroy' resources :users end
#GemFile source 'https://rubygems.org' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" end # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.1.4' gem 'bcrypt' , '3.1.11' gem 'bootstrap-sass','3.3.7' # Use Puma as the app server gem 'puma', '~> 3.9.1' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0.6' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 3.2.0' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby gem 'jquery-rails' , '4.3.1' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.2.2' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5.0.1' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.7.0' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 3.0' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development group :development, :test do gem 'sqlite3','1.3.13' # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', '9.0.6' ,platforms: :mri end group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. gem 'web-console', '>= 3.5.1' gem 'listen', '3.1.5' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' , '2.0.2' gem 'spring-watcher-listen', '~> 2.0.1' end group :test do gem 'rails-controller-testing' , '1.0.2' gem 'minitest-reporters' , '1.1.14' gem 'guard' , '2.13.0' gem 'guard-minitest' , '2.4.4' #gem 'minitest' , '~> 5.10.1' end group :production do gem 'pg' , '0.18.4' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
試したこと
1.ブランチを変更して、ログインができていたプロジェクトまで戻ったりもしましたが、同じ現象が起きました。
2.createアクションが呼ばれてすぐ、ログを出力する記述を施して実行しましたが、ログは吐かれていませんでした。
※上記から察するに、Post通信を起こす前に問題が起きているっぽい
3.フォームヘルパーをform_forからform_withに変更(前者が非推奨になっているため)しましたが、特に現状変わりませんでした。
4.同じくPost通信が発生するユーザ登録も、上記と同じ現象で遷移できなくなっていました。
補足情報(FW/ツールのバージョンなど)
ruby -v -- 2.6.3p62
rails -v -- 5.1.7
足りない情報などご指摘いただきましたら補足いたします。
上記、何かご存知の方いらっしゃいましたら、ご教示いただけますと幸いです・・・
あなたの回答
tips
プレビュー