現在devise(4.2.0)を導入して、認証するemail,Password以外にも名前や住所などを同時に入力して登録できるよう実装しています。
問題としては、新たに追加したカラム(:name, :companyname, :address, :tel, :email)にパラメータが送られず、DBに保存されないことです。
Ruby
1#application_controller.rb 2 3class ApplicationController < ActionController::Base 4 # Prevent CSRF attacks by raising an exception. 5 # For APIs, you may want to use :null_session instead. 6protect_from_forgery with: :exception 7before_action :configure_permitted_parameters, if: :devise_controller? 8 9protected 10 11 # If you have extra params to permit, append them to the sanitizer. 12 def after_sign_up_path_for(resource) 13 users_path # サインイン後のリダイレクト先URL 14 end 15 16 def after_sign_in_path_for(resource) 17 users_path # ログイン後のリダイレクト先URL 18 end 19 20 def configure_permitted_parameters 21 devise_parameter_sanitizer.permit(:sign_up) do |user_params| 22 user_params.permit(:password, :password_confirmation, :name, :companyname, :address, :tel, :email) 23 end 24 end 25 26 def after_sign_out_path_for(resource) 27 user_session_path # サインアウト後のリダイレクト先URL 28 end 29end
Ruby
1 2#viwes/users/registrations/new.html.erb 3 4<h2>Sign up</h2> 5 6<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> 7 <%= devise_error_messages! %> 8 9 10 <div class="field"> 11 <%= f.label :email %><br /> 12 <%= f.email_field :email, autofocus: true %> 13 </div> 14 15 <div class="field"> 16 <%= f.label :password %> 17 <% if @minimum_password_length %> 18 <em>(<%= @minimum_password_length %> characters minimum)</em> 19 <% end %><br /> 20 <%= f.password_field :password, autocomplete: "off" %> 21 </div> 22 23 <div class="field"> 24 <%= f.label :password_confirmation %><br /> 25 <%= f.password_field :password_confirmation, autocomplete: "off" %> 26 </div> 27 28<div class="field"> 29 <%= f.label :name %><br> 30 <%= f.text_field :name %> 31 </div> 32 <div class="field"> 33 <%= f.label :companyname %><br> 34 <%= f.text_field :companyname %> 35 </div> 36 <div class="field"> 37 <%= f.label :address %><br> 38 <%= f.text_field :address %> 39 </div> 40 <div class="field"> 41 <%= f.label :tel %><br> 42 <%= f.text_field :tel %> 43 </div> 44 45 <div class="actions"> 46 <%= f.submit "Sign up" %> 47 </div> 48<% end %> 49 50<%= render "users/shared/links" %> 51
エラー等は特に表示されないのですが、何が原因なのかご教示いただければ幸いです。
宜しくお願い致します。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。