简体   繁体   中英

no implicit conversion of nil into String during update rails 4

I am trying to update password. Here is my form

<%= form_for(:profile, url: {action: 'change_password'}, remote: true ) do |f| %>
<%= f.password_field :password %>
<% end %>

This is my controller

def change_password
    @customer = Customer.find session[:customer_id]
    unless params[:profile].nil?
      password = params[:password]
      @customer.update_attribute(:password, password)
    end
  end

During registration I have encrypted and saved my password. Here is the model I have

def self.generate_hash password
        Digest::SHA1.hexdigest password   #Showing error in this line
    end

    def generate_password
        self.password = Customer.generate_hash self.password
    end

But while updating the password getting error as

no implicit conversion of nil into String

Try

def self.generate_hash password
    Digest::SHA1.hexdigest password.to_s   #Showing error in this line
end

Update

Try replacing

password = params[:password]

by

password = params[:profile][:password]

This may be causing password to hold nil.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM