Andre Cubeta
2010-Aug-09 07:17 UTC
Devise :current_password validations and checking (how???)
Hi Guys, In my devise applications in Rails 3, I created a separate form under my SettingsController class of which it handles the ''Change Password'' of the User Model, so i can manipulate the current_user in the SettingsController. Now, I followed the set-up in the Devise/Views on how to update the form using ''Change password'' and either way update User for current_password change but I''ve no luck on the implementation. I need you experties My question is, how to check the my :current_password to the params[:user][:current_password] I tried to submit in the form. Meaning how can the devise check the submitted params[:user][:current_password] to match and validate on the current_user.pasword This is my code, i''m using HAML I''m also using config.encryptor = :restful_authentication_sha1 since I migrated from auth_logic to devise authentication tool "Views/Settings/change_password.haml" goes like this *************************************************************** %aside#sidebar %nav.leftbar %ul %li.pwd= link_to "Password", change_password_path %section#content.w.r = form_for(@user, :as => :user, :url => change_password_path(:user)) do |f| %h1 Change your password %fieldset %div = f.hidden_field :reset_password_token %div = f.label :current_password = f.password_field :current_password, :autofocus => true %div = f.label :password = f.password_field :password %div = f.label :password_confirmation = f.password_field :password_confirmation .action = f.submit "Change password" or = link_to "Cancel", settings_path *************************************************************** "SettingsController" goes like this below using change_password method *************************************************************** def change_password if params[:user] begin current_user.update_attributes!(:password => params[:user][:password]) flash[:notice] = "Password successfully changed" redirect_to settings_path rescue Exception => msg flash[:notice] = msg end else @user = current_user end end *************************************************************** -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.