plataformatec/devise — Issue #1572: Permitir usuários editarem uma conta sem prover uma senha
Author: ricardopacheco
Created: 2012-01-16 08:37:43+00:00
State: open

Segui esses passos a risca:

https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-account-without-providing-a-password

E não consigo de jeito algum alterar um usuário sem senha! Meu código tem apenas um resource chamado User.

Código do meu modelo

class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me,
:name, :cell, :phone, :description, :actived, :admin, :partner

has_many :imoveis, :dependent => :destroy

validates_uniqueness_of :email, :message => "ja existente. tente outro email"
validates :email, :password, :presence => { :message => "precisa ser preenchido." }

validates :name, :description, :presence => { :message => "precisa ser preenchido." }
validates :cell, :phone, :presence => { :message => "precisa ser preenchido." }

def update_with_password(params={})
current_password = params.delete(:current_password)

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

result = if params[:password].blank? and if params[:password].blank? || valid_password?(current_password)
update_attributes(params)
else
self.attributes = params
self.valid?
self.errors.add(:current_password, current_password.blank? ? :blank : :invalid)
false
end

clean_up_passwords
result
end

end