0
votes

I install devise gem and wanted to add some columns on registration page.

app/controllers/users/registrations_controller.rb

class Users::RegistrationsController < Devise::RegistrationsController
before_action :configure_sign_up_params, only: [:create]


protected

def configure_sign_up_params
devise_parameter_sanitizer.permit(:sign_up){|u| u.permit(:company_id, :name, :email, :profile, :prefecture_id, :address, :password, :password_confirmation)}
end

app/views/devise/registrations/new.html.erb

<%= simple_form_for(resource, as: resource_name, url:registration_path(resource_name)) do |f| %>
<%= f.error_notification %>

<div class="form-inputs">
<%= f.label :campany_id %><br>
<%= f.collection_select :campany_id, Campany.all, :id, :name, include_blank: true %>
<%= f.input :name, required: true, autofocus: true %>
<%= f.inneput :email, paceholder:"メールアドレス", required: true, autofocus: true %>
<%= f.input :profile, required: true, autofocus: true %>
*<%= f.label :prefecture_id %><br>
<%= f.collection_select :prefecture_id, JpPrefecture::Prefecture.all, :code, :name %>
<%= f.input :address, required: true, autofocus: true %>
<%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
<%= f.input :password_confirmation, required: true %>
</div>

<div class="form-actions">
<%= f.button :submit, "新規登録" %>
</div>
<% end %>

config/routes.rb

devise_for :users, controllers: { 
registrations: 'users/registrations' 
}

When I filled out the form and submitted. It show " ArgumentError:wrong number of arguments (given 0, expected 1)" this error! Is there some wrong?

Thank you!

1
Can you please add error trace? - Rokibul Hasan
Sorry, Do you mean this? requirebin/rails rescue LoadError => e raise unless e.message.include?('spring') end APP_PATH = File.expand_path('../../config/application', FILE) require_relative '../config/boot' require 'rails/commands' <top (required)>bin/rails rescue LoadError => e raise unless e.message.include?('spring') end APP_PATH = File.expand_path('../../config/application', FILE) require_relative '../config/boot' require 'rails/commands' - JiaPing
<top (required)>bin/spring lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) spring = lockfile.specs.detect { |spec| spec.name == "spring" } if spring Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path gem 'spring', spring.version require 'spring/binstub' end end - JiaPing
can you specify on which line this error occuring check your log inside log folder in your rails root directory you can find a file with your environment. - Vishal Taj PM
I checked my log and saw this line. ArgumentError - wrong number of arguments (given 0, expected 1): devise (4.2.1) lib/devise/models/database_authenticatable.rb:157:in `password_digest' Is this the reason for the error? - JiaPing

1 Answers

0
votes

In new.html.erb, for input email your input spelling should be f.input, also you have given campany_id but in controller you have used company_id.

And in controller:

def configure_sign_up_params
devise_parameter_sanitizer.permit(:sign_up){|u| u.permit(:company_id, :name, :email, :profile, :prefecture_id, :address)}
end

You only need to permit parameters which have been added by you. You do not need to permit password or confirm_password. Also all the parameters permitted or which are there in form need to be in your table.

Hope this helps.