How can I get devise to add a username with rails 5 -
there previous posts discussing how add username devise model. unfortunately, these posts not discuss how setup views. mainly, i'm interested in updating
devise/registrations/edit.html.erb
file. in it, have added following lines
<div class="field"> <%= f.label :username %><br /> <%= f.text_field :username %> </div>
to allow users update username. unfortunately, when save form, username not update. why happening?
i checked comment above, if want update user can use user controller (not device registration) , below code user controller
class userscontroller < applicationcontroller def edit @user = user.find(params[:id]) end def update # devise if params[:user][:password].blank? params[:user].delete(:password) params[:user].delete(:password_confirmation) end @user = user.find(params[:id]) if @user.update_attributes(user_params) flash[:success] = 'user changed' sign_out_and_redirect(@user) # push user sign out else flash[:error] = @user.errors.full_messages[0] redirect_to users_path end end private # white list parameter def user_params params.require(:user).permit( :username, :password, :password_confirmation, :email end end
Comments
Post a Comment