Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing block to for strong parameters breaks code #758

Closed
erikflood opened this issue Oct 31, 2016 · 5 comments
Closed

Passing block to for strong parameters breaks code #758

erikflood opened this issue Oct 31, 2016 · 5 comments

Comments

@erikflood
Copy link

erikflood commented Oct 31, 2016

If I pass anything but scalar values as strong parameters, but instead passes a block, it will break the devise_token_auth gem:

devise_parameter_sanitizer.permit(:sign_in) do |user_params|
    user_params.permit(:username, :email)
  end

will result in the following error

NoMethodError (undefined method 'each' for #<Proc:0x007fd1f03b7f08>):

devise_token_auth (0.1.39) app/controllers/devise_token_auth/application_controller.rb:20:in 'params_for_resource'
devise_token_auth (0.1.39) app/controllers/devise_token_auth/registrations_controller.rb:101:in 'sign_up_params'
devise_token_auth (0.1.39) app/controllers/devise_token_auth/registrations_controller.rb:199:in 'validate_sign_up_params'
@mzane42
Copy link

mzane42 commented Jan 25, 2017

Hi @erikflood, did you find solution ?

@dlanileonardo
Copy link

🆙

@fabianprado
Copy link

fabianprado commented Feb 12, 2017

Hi, anyone have a workaround to this? I need to receive nested attributes and this should be the way.

EDIT: actually I misunderstood the doc; it is not necessary to pass a block in order to permit nested attributes

@stratigos
Copy link
Contributor

stratigos commented Feb 17, 2017

Yes as @fabianprado was pointing out - the current workaround is to not pass in a block to devise_parameter_sanitizer, but declare all white listed params in the :keys hash of second argument, i.e.,:

def configure_permitted_parameters
  devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
end

@zachfeldman
Copy link
Contributor

Workaround posted, closing for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants