ruby - Saving custom fields in devise User model in rails 4 -
i made devise user model , added additional fields it. when create , account works fine, email, pw , pw conf.
i want allow user go edit page , fill in optional additional fields. but, when submit, saved nil.
class registrationscontroller < devise::registrationscontroller before_action :configure_permitted_parameters, if: :devise_controller? def configure_permitted_parameters devise_parameter_sanitizer.for(:sign_in){ |u| u.permit(:email, :password) } devise_parameter_sanitizer.for(:sign_up){ |u| u.permit(:name, :username, :about, :email, :password, :password_confirmation)} devise_parameter_sanitizer.for(:account_update){ |u| u.permit(:name, :username, :about, :email, :password, :password_confirmation) } end def update self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key) if resource.update_with_password(user_params) if is_navigational_format? flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ? :update_needs_confirmation : :updated set_flash_message :notice, flash_key end sign_in resource_name, resource, :bypass => true respond_with resource, :location => after_update_path_for(resource) else clean_up_passwords resource respond_with resource end end def user_params params.require(:user).permit(:email, :password, :current_password, :password_confirmation, :name, :username, :about) end end
i output in console,
activerecord::schemamigration load (0.1ms) select "schema_migrations".* "schema_migrations" processing devise::registrationscontroller#update html parameters: {"utf8"=>"✓", "authenticity_token"=>"eg8ftctbohug2uwuviqmy7ktsmyy1nmaxqtfc0li+eq=", "user"=>{"email"=>"a@a.com", "name"=>"aaron", "username"=>"", "about"=>"", "password"=>"[filtered]", "password_confirmation"=>"[filtered]", "current_password"=>"[filtered]"}, "commit"=>"update"} user load (2.2ms) select "users".* "users" "users"."id" = ? limit 1 [["id", 1]] unpermitted parameters: name, username,
but nothing saved in database when check in console (with user.last). stuck, , have looked , have no idea wrong...
in rails4 have strong parameters please
add following line application_controller.rb
before_filter :configure_devise_params, if: :devise_controller? def configure_devise_params devise_parameter_sanitizer.for(:sign_up) |u| u.permit(:first_name, :last_name, :gender, :email, :password, :password_confirmation) end end
Comments
Post a Comment