質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

439閲覧

Railsチュートリアル7章で、新規登録時の画面に移動しない

Shmupeiii

総合スコア105

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2022/01/16 11:23

前提・実現したいこと

Railsチュートリアル7章7.3.3エラーメッセージ
を行っていたところ、フォーム送信時にエラーメッセージを表示するためのパーシャルが表示されなくなった。エラーからすると、_error_messages.htmlだと感じたが、コードがチュートリアルと同じなので、解決できず。
分かる方がいればよろしくお願いいたします。

Githubのコード
heroku
(herokuは、/signup から飛べます。)

発生している問題・エラーメッセージ

エラーメッセージ(ローカル環境)
イメージ説明

Started GET "/signup" for 127.0.0.1 at 2022-01-16 20:18:27 +0900 Processing by UsersController#new as HTML Rendering layout layouts/application.html.erb Rendering users/new.html.erb within layouts/application Rendered shared/_error_messages.html.erb (Duration: 9.7ms | Allocations: 2018) Rendered users/new.html.erb within layouts/application (Duration: 15.9ms | Allocations: 3081) Rendered layout layouts/application.html.erb (Duration: 16.4ms | Allocations: 3161) Completed 500 Internal Server Error in 26ms (ActiveRecord: 0.0ms | Allocations: 4058) ActionView::Template::Error (undefined method `errors' for nil:NilClass): 1: <% if @user.errors.any? %> 2: <div id="error_explanation"> 3: <div class="alert alert-danger"> 4: The form contains <%= pluralize(@user.errors.count, "error") %>. app/views/shared/_error_messages.html.erb:1 app/views/users/new.html.erb:7 app/views/users/new.html.erb:6
#users_controller.rb class UsersController < ApplicationController def show @user = User.find(params[:id]) end def create @user = User.new(user_params) if @user.save redirect_to @user else render 'new' end end private def user_params params.require(:user).permit(:name, :email, :password, :password_confirmation) end end

Ruby

1#user/new.html 2<% provide(:title, 'Sign up') %> 3<h1>Sign up</h1> 4 5<div class="row"> 6 <div class="col-md-6 col-md-offset-3"> 7 <%= form_with(model: @user, local: true) do |f| %> 8 <%= render 'shared/error_messages' %> 9 10 <%= f.label :name %> 11 <%= f.text_field :name, class: 'form-control' %> 12 13 <%= f.label :email %> 14 <%= f.email_field :email, class: 'form-control' %> 15 16 <%= f.label :password %> 17 <%= f.password_field :password, class: 'form-control' %> 18 19 <%= f.label :password_confirmation, "Confirmation" %> 20 <%= f.password_field :password_confirmation, class: 'form-control' %> 21 22 <%= f.submit "Create my account", class: "btn btn-primary" %> 23 <% end %> 24 </div> 25</div>

該当のソースコード

#_error_messages.html <% if @user.errors.any? %> <div id="error_explanation"> <div class="alert alert-danger"> The form contains <%= pluralize(@user.errors.count, "error") %>. </div> <ul> <% @user.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %>

補足情報(FW/ツールのバージョンなど)

source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '2.6.5' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main' gem 'rails', '~> 6.1.4', '>= 6.1.4.1' gem 'bootstrap-sass', '3.4.1' gem 'bcrypt', '3.1.13' # Use sqlite3 as the database for Active Record # gem 'sqlite3', '~> 1.4' # 開発・テスト環境ではSQLite3を使う group :development, :test do gem 'sqlite3', '~> 1.4' end # 本番環境ではPostgresqlを使う group :production do gem 'pg', '1.1.4' end # Use Puma as the app server gem 'puma', '~> 5.0' # Use SCSS for stylesheets gem 'sass-rails', '>= 6' # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker gem 'webpacker', '~> 5.0' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.7' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 4.0' # Use Active Model has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use Active Storage variant # gem 'image_processing', '~> 1.2' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.4.4', require: false group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] end group :development do # Access an interactive console on exception pages or by calling 'console' anywhere in the code. gem 'web-console', '>= 4.1.0' # Display performance information such as SQL time and flame graphs for each request in your browser. # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md gem 'rack-mini-profiler', '~> 2.0' gem 'listen', '~> 3.3' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' end group :test do # Adds support for Capybara system testing and selenium driver gem 'capybara', '>= 3.26' gem 'selenium-webdriver' # Easy installation and use of web drivers to run system tests with browsers gem 'webdrivers' gem 'minitest', '5.11.3' gem 'minitest-reporters', '1.3.8' gem 'rails-controller-testing', '1.0.4' gem 'guard', '2.16.2' gem 'guard-minitest', '2.4.6' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

usersコントローラーにnewアクションがないからではないでしょうか?

投稿2022/01/16 17:24

ohoh5454

総合スコア92

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Shmupeiii

2022/01/17 11:05

初歩的なミスでした。 回答ありがとうございます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問