ruby on rails - syntax error, unexpected ',', expecting => ...| u.permit( roles: [], :email,:password, :password_confirma... ... ^ -


i using gem 'devise' in project. difference between these 2 lines of code :

 devise_parameter_sanitizer.for(:sign_up)  { |u| u.permit( :email, :password, :password_confirmation, roles: [] ) } 

and

devise_parameter_sanitizer.for(:sign_up)  { |u| u.permit(roles: [], :email, :password, :password_confirmation ) } 

because when tried second 1 getting error:

syntax error, unexpected ',', expecting => ...| u.permit( roles: [], :email,:password, :password_confirma... ... ^ 

ruby has special syntax sugar argument, hash. must pass last.

this

u.permit( :email, :password, :password_confirmation, roles: [] ) 

essentially means this

u.permit( :email, :password, :password_confirmation, { roles: [] } ) 

in second example, you're trying pass first argument, confuses ruby parser. use first form.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -