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
Post a Comment