Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 5, Undefined method `for' for #<Devise on line devise_parameter_sanitizer.for

I am working with Rails 5

I aded new field username in model User.

class Users::RegistrationsController < Devise::RegistrationsController   before_action :configure_permitted_parameters    protected    def configure_permitted_parameters     devise_parameter_sanitizer.for(:sign_up).push(:username)     end end 

During registration is displayed error: undefined method `for' for # Did you mean? fork

Trace:

NoMethodError (undefined method `for' for # Did you mean? fork):

app/controllers/users/registrations_controller.rb:7:in `configure_permitted_parameters'   Rendering /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout   Rendering /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb   Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (5.0ms)   Rendering /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb   Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.9ms)   Rendering /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb   Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.2ms)   Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.rc1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (118.1ms) 

Who can help? How solve this problem?

like image 776
Dmitriy Avatar asked May 20 '16 08:05

Dmitriy


Video Answer


1 Answers

According to the documentation:

The Parameter Sanitaizer API has changed for Devise 4

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 
like image 194
Philidor Avatar answered Sep 19 '22 10:09

Philidor