开发者

When editing User with Devise why does it pre-fill the new password field with the User's current password, and how to override

Please forgive this relatively newbie question, but I could use some help.

I've installed the Devise Gem on my User model with only minor changes to the Devise views and no changes to the controller. Still, I am having an issue that I can't solve.

The accounts/edit url (I've defined the routes using, 'devise_for :users, :path => "accounts"') brings up the user edit form as expected. But, the field to insert a new password is pre-filled with the user's current password (with type = password, of course). I don't want this field to be pre-filled with anything. So, I'd like the field to be blank whenever the form is render开发者_运维百科ed. I've tried the following change in the devise/registration/edit view, but it didn't replace the pre-filled password with a blank string, like I had hoped:

<p><span style = "font-weight:bold; padding:0"><%= f.label "New Password" %></span><br />
<%= f.password_field :password, :value => ""%>
  <i>(just leave this blank if you don't want to change your current password)</i></p>

I'm sure that there is an easy fix, but I just can't find it anywhere. Help would be greatly appreciated.


Give the input tag the attribute autocomplete= "off" and see if that helps.

<%= f.password_field :password, :autocomplete => 'off'  %>

http://blog.teksol.info/2005/11/16/prevent-field-autocompletion-in-rails-applications


not an easy way I'm afraid :(. I edited the user class removing the :validatable devise feature and added this by hand.

validates_presence_of :password, :if => :password_required?
validates_confirmation_of :password, :if => :password_required?
validates_length_of :password, :within => 6..30, :allow_blank => true, :if => :password_required?

and this method so the validation only runs when

def password_required?
    !persisted? || !password.nil? || !password_confirmation.nil?
end

and on the users_controller in the update method only updates the password if it is present

if params[:user][:password].blank?
  params[:user].delete(:password)
  params[:user].delete(:password_confirmation)
end

hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜