Editing/Updating user not working when using has_secure_password in Rails 4 -
I am using Michael Hart so that my own user can become an atom system. When creating a new user, everything is working fine, while trying to update a user, it is not able to understand things until I'm using the has_secure_password
method so I can pick it up And I worry about encrypting it. But when I update, there is some strange behavior.
The important part is that I can update and authenticate a user without entering any password, but if I do not enter a password and a confirmation, then a confirmation requirement for it is. If I enter only a confirmation password, then there is no update with the error. Now that the is_saker_password
seems to be doing that part, why not make it while updating it Used to be? What I did not add to my user model is the presence recognition due to this line in the tutorial:
Attendance attributes for the password and its confirmation is automatically added by the_secure_password.
I know that there are similar questions, but no strong parameters can apply, which is my guess why this is not working for me some of my code below Have been given.
User Controller
Diff Editing @ User = User.Fund (Perm [: ID]) End Def Update @ User = User.Fund (Param [: id]) # Paramas [: User] [: Password]. Blanc? #Render 'edit' # return # end if @ user.update (user_params) redirect_to @user, notice: 'User successfully updated' and edit 'render', notice: 'Failed to update profile.' (Android), android android, youtube, android, url, / strong> class user & lt; ActiveRecord :: Base before_save {self.email = email.downcase} has_secure_password before_create: create_remember_token Valid: Username, Attendance: Right, Length: {Max: 255, Minimum: 5}, Format: {with: / \ A [a- ZA] -Z0- 9] * \ z /, Message: "Only letters and numbers can occur." }, Specify: true VALID_EMAIL_REGEX = /\A[\w+\-.]+@[az.d.-.]+\.[az]+\z/i is valid: email, presence: true, format: { With: VALID_EMAIL_REGEX} # other user stuff.
Edit form
& lt; Div class = "col-xs-8 col-xs-offset-2" & gt; & Lt;% = form_for (@user ,: html = & gt; {: class = & gt; 'good'}) do. F | & Gt%; & Lt; Div class = "form-group" & gt; & Lt;% = f.label: Username% & gt; & Lt; Br / & gt; & Lt;% = f.text_field: Username, Category: Form-Control '% & gt; & Lt; / Div & gt; & Lt; Div class = "form-group" & gt; & Lt;% = f.label: Phone% & gt; & Lt; Br / & gt; & Lt;% = f.phone_field: Phone, Class: 'Form-Control'% & gt; & Lt; / Div & gt; & Lt; Div class = "form-group" & gt; & Lt;% = f.label: bio% & gt; & Lt; Br / & gt; & Lt;% = f.text_area: bio, category: 'form-control'% & gt; & Lt; / Div & gt; & Lt; Div class = "form-group" & gt; & Lt;% = f.label: email% & gt; & Lt; Br / & gt; & Lt;% = f.email_field: email, category: 'form-control'% & gt; & Lt; / Div & gt; & Lt; Div class = "form-group" & gt; & Lt;% = f.label: Password% & gt; & Lt; Br / & gt; & Lt;% = f.password_field: password, category: 'form-control'% & gt; & Lt; / Div & gt; & Lt; Div class = "form-group" & gt; & Lt;% = f.label: password_confirmation% & gt; & Lt; Br / & gt; & Lt;% = f.password_field: password_confirmation, class: 'form-control'% & gt; & Lt; / Div & gt; & Lt; Div class = "form-group" & gt; & Lt;% = f.submit "Update", Category: 'BTN BTN-Default'% & gt; & Lt; / Div & gt; & Lt;% end% & gt; & Lt; / Div & gt;
Since it is a update
code> create It may be that legalization is not operational.
From:
Validations for the presence of a password while creating , confirming secure_password.rb
Code
option = {}) ... if options.fetch {| M M.password.present? } Validates_presence_of: Password: at: = & gt; : Validates_presence_of Create: password_confirmation, if: lambda {| M M.password.present? } End ... end
Comments
Post a Comment