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

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

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

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

Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby

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

Q&A

0回答

3141閲覧

Unpermitted parameter: :nameを解決したい

退会済みユーザー

退会済みユーザー

総合スコア0

Ruby on Rails 5

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

Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby

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

0グッド

0クリップ

投稿2018/11/23 06:20

どなたかご存知の方、ご助力願います。

実現したいこと

deviseのgemを使い、ログイン時に名前のカラム(name)とパスワードのカラム(password)を使いログインすること検討しています。

やったこと

deviseのgemをインストールしています。
Userモデルを作成する時にnameカラムを追加しています。
application_controllerconfigure_permitted_parametersを記載しています。

### 現在の状況
新規登録をする際、nameが保存されているのをターミナル実行結果にて確認しました。

Cannot render console from 10.0.2.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 Processing by Devise::RegistrationsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"U3+6qatJ1avy6JiCAP5tUZuVG/ifM8F+2vVPdGztNy5WpiUpu54MNPqP5zKZkYwdf8bfiQLUK0YmU+5EZXtz0Q==", "user"=>{"name"=>"aaaa", "email"=>"phone@phone", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"} (0.1ms) begin transaction ↳ /var/lib/gems/2.5.0/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98 User Exists (1.5ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = ? LIMIT ? [["email", "phone@phone"], ["LIMIT", 1]] ↳ /var/lib/gems/2.5.0/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98 User Create (5.2ms) INSERT INTO "users" ("email", "encrypted_password", "name", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?) [["email", "phone@phone"], ["encrypted_password", "$2a$11$B1aGaxEVFYgsFefnGCRal.VxHzr.amza.cSMxPOU8AMgdyVFEHUDC"], ["name", "aaaa"], ["created_at", "2018-11-23 05:46:08.374697"], ["updated_at", "2018-11-23 05:46:08.374697"]] ↳ /var/lib/gems/2.5.0/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98 (3.7ms) commit transaction ↳ /var/lib/gems/2.5.0/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98 Redirected to http://localhost:3000/

しかし、ログインしようとするとターミナル実行結果は下記の通りになります

Processing by Devise::SessionsController#new as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"2lrKDZUeTXXBXsDgXZ5YYmBBCkS5F5JDOLBKEOy8LyU0klmq/O99DqNipe6W3n7qlwtNmCutWbE454QXM6zRSQ==", "user"=>{"name"=>"aaaa", "password"=>"[FILTERED]", "remember_me"=>"1"}, "commit"=>"Log in"} Unpermitted parameter: :name Rendering devise/sessions/new.html.erb within layouts/application Rendered devise/shared/_links.html.erb (1.5ms) Rendered devise/sessions/new.html.erb within layouts/application (30.8ms) Completed 200 OK in 614ms (Views: 470.5ms | ActiveRecord: 0.0ms)

↓application_controller.rb↓

Ruby

1class ApplicationController < ActionController::Base 2 before_action :configure_permitted_parameters, if: :devise_controller? 3 4 protected 5 6 def configure_permitted_parameters 7 devise_parameter_sanitizer.permit(:sign_up, keys: [:username]) 8 devise_parameter_sanitizer.permit(:sign_in, keys: [:username]) 9 end 10 11end

↓schema.rb↓

ruby

1# This file is auto-generated from the current state of the database. Instead 2# of editing this file, please use the migrations feature of Active Record to 3# incrementally modify your database, and then regenerate this schema definition. 4# 5# Note that this schema.rb definition is the authoritative source for your 6# database schema. If you need to create the application database on another 7# system, you should be using db:schema:load, not running all the migrations 8# from scratch. The latter is a flawed and unsustainable approach (the more migrations 9# you'll amass, the slower it'll run and the greater likelihood for issues). 10# 11# It's strongly recommended that you check this file into your version control system. 12 13ActiveRecord::Schema.define(version: 2018_11_20_232654) do 14 15 create_table "users", force: :cascade do |t| 16 t.string "email", default: "", null: false 17 t.string "encrypted_password", default: "", null: false 18 t.string "reset_password_token" 19 t.datetime "reset_password_sent_at" 20 t.datetime "remember_created_at" 21 t.integer "sign_in_count", default: 0, null: false 22 t.datetime "current_sign_in_at" 23 t.datetime "last_sign_in_at" 24 t.string "current_sign_in_ip" 25 t.string "last_sign_in_ip" 26 t.string "name" 27 t.datetime "created_at", null: false 28 t.datetime "updated_at", null: false 29 t.index ["email"], name: "index_users_on_email", unique: true 30 t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true 31 end 32 33end 34

↓sessions/new.html.erb↓

Ruby

1<h2>Log in</h2> 2 3<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> 4 <div class="field"> 5 <%= f.label :name %><br /> 6 <%= f.text_field :name, autofocus: true, autocomplete: "name" %> 7 </div> 8 9 <div class="field"> 10 <%= f.label :password %><br /> 11 <%= f.password_field :password, autocomplete: "current-password" %> 12 </div> 13 14 <% if devise_mapping.rememberable? -%> 15 <div class="field"> 16 <%= f.check_box :remember_me %> 17 <%= f.label :remember_me %> 18 </div> 19 <% end -%> 20 21 <div class="actions"> 22 <%= f.submit "Log in" %> 23 </div> 24<% end %> 25 26<%= render "devise/shared/links" %> 27

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

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

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

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問