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

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

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

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

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

Q&A

1回答

1513閲覧

ユーザーの新規登録ができない

sy0306

総合スコア0

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

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

0グッド

0クリップ

投稿2020/11/24 04:15

編集2020/11/24 05:13

前提・実現したいこと

新規登録をしたい

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

ターミナルにはROLLBACKが出てくる

エラーメッセージ Started POST "/users" for ::1 at 2020-11-24 14:01:33 +0900 Processing by Devise::RegistrationsController#create as HTML Parameters: {"authenticity_token"=>"7NS6bhHq/tRHNV89oiL1xBVXrFqtrj+lKzfdgA0IfRs99Ghi6ftQMWwUIfigs7JBJO0h9h4UMMRySbdXSBx6KQ==", "user"=>{"email"=>"a@a", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "name"=>"a", "profile"=>"a", "occupation"=>"a", "position"=>"a"}, "commit"=>"新規登録"} (0.2ms) BEGIN User Exists? (0.3ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = BINARY 'a@a' LIMIT 1 (0.1ms) ROLLBACK Rendering devise/registrations/new.html.erb within layouts/application Rendered devise/registrations/new.html.erb within layouts/application (Duration: 1.8ms | Allocations: 1233) [Webpacker] Everything's up-to-date. Nothing to do Completed 200 OK in 265ms (Views: 35.8ms | ActiveRecord: 0.7ms | Allocations: 20266)

該当のソースコード

ruby

1(new.html.erb) 2<div class="main"> 3 <div class="inner"> 4 <div class="form__wrapper"> 5 <h2 class="page-heading">ユーザー新規登録</h2> 6 7 <%# 「モデル名」にはUserモデルであれば@userを渡しましょう。%> 8 <%# 「新規登録機能へのパス」は、devise導入後にrails routesを実行してdevise/registrations#createへのパスを確認し、記載してください。 %> 9 <%= form_with model: @user, url: user_registration_path ,id: 'new_user', class: 'new_user', local: true do |f| %> 10 11 <div class="field"> 12 <%= f.label :email, "メールアドレス" %><br /> 13 <%= f.email_field :email, autofocus: true, autocomplete: "email" %> 14 </div> 15 16 <div class="field"> 17 <%= f.label :password, "パスワード(6文字以上)" %><br /> 18 <%= f.password_field :password, autocomplete: "new-password" %> 19 </div> 20 21 <div class="field"> 22 <%= f.label :password_confirmation, "パスワード再入力" %><br /> 23 <%= f.password_field :password_confirmation, autocomplete: "new-password" %> 24 </div> 25 26 <div class="field"> 27 <%= f.label :name, "ユーザー名" %><br /> 28 <%= f.text_field :name %> 29 </div> 30 31 <div class="field"> 32 <%= f.label :profile, "プロフィール" %><br /> 33 <%= f.text_area :profile, class: :form__text %> 34 </div> 35 36 <div class="field"> 37 <%= f.label :occupation, "所属" %><br /> 38 <%= f.text_area :occupation, class: :form__text %> 39 </div> 40 41 <div class="field"> 42 <%= f.label :position, "役職" %><br /> 43 <%= f.text_area :position, class: :form__text %> 44 </div> 45 46 <div class="actions"> 47 <%= f.submit "新規登録", class: :form__btn %> 48 </div> 49 <% end %> 50 </div> 51 </div> 52</div>

ruby

1(user.rb) 2class User < ApplicationRecord 3 # Include default devise modules. Others available are: 4 # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 5 devise :database_authenticatable, :registerable, 6 :recoverable, :rememberable, :validatable 7 has_many :prototype 8 9 validates :name, presence: true 10 validates :profile, presence: true 11 validates :occupation, presence: true 12 validates :position, presence: true 13end

ruby

1routes.rb 2Rails.application.routes.draw do 3 devise_for :users 4 # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html 5 get 'prototype/users' 6 root to: "prototype#index" 7 resources :prototype, only: [:index, :new, :create] 8 resources :users, only: [:edit, :update, :show] 9end 10

試したこと

コードなど見直し

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

ここにより詳細な情報を記載してください。

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

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

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

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

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

m.ts10806

2020/11/24 04:27

Ruby on Rails もタグに追加してください。 Rubyする人が全てRailsするとは限りません。
m.ts10806

2020/11/24 04:30

あと、それぞれどのようなつもりでコードを記載していますか? ログイン後にどうなるつもりでどこのコードをどのように書いているのか。 自身がどこまで分かっていて何が分からないかというところも具体的に記載してください。 というか「ログインしても」と仰っていますが、ビューはユーザーの新規登録の画面になっています。どういうつもりで「ログイン」と書かれたのでしょうか。
m.ts10806

2020/11/24 05:06

>ターミナルにはROLLBACKが出てくる 念のためその出力内容も提示してください
sy0306

2020/11/24 05:14

出力内容を追加しました
guest

回答1

0

コントローラーの記述が無いので恐らくにはなりますが、
app/controllers/application_controller.rb
にストロングパラムスが無いためかと思います。
以下記述例

class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:username]) end end

↑詳しくは一次ソースをご確認下さい。
https://github.com/heartcombo/devise#strong-parameters

投稿2020/11/25 04:56

tomtomtomtom

総合スコア563

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

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

tomtomtomtom

2020/11/27 07:46

その後問題は解決されましたでしょうか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問