我有用于在网上商店激活新客户帐户的自定义控制器操作。我有一个模型叫customer.rb
. 该模型生成一个密钥并向客户发送一个激活链接。该链接被路由到customers_controller.rb
以下操作:
def activate_customer
@customer = Customer.find(params[:customer_id])
if @customer.present?
if @customer.activation_key == params[:activation_key]
@customer.activated = true
@customer.save
redirect_to :cart
else
redirect_to :root
end
else
redirect_to :root
end
end
我第一次尝试没有@customer.save
但记录没有更新。我之前和之后都提出过,@customer.activated = true
这一切似乎都很好。唯一的问题是记录没有更新。我还检查了一个可能的attar_accessible
问题,但不是这样(我attr_accessible
完全关闭检查)。有任何想法吗?提前谢谢!
*编辑:检查值@customer.save
,返回false
...
*编辑:
问题似乎是客户模型上的密码验证。验证如下所示:
# Validations
validates_presence_of :title, :country, :zipcode, :city, :street, :number, :first name, :lastname
validates :email, :presence => true, :uniqueness => true, :email => true
validates_confirmation_of :password, :unless => :validate?
validates_presence_of :password
任何想法如何跳过此特定控制器操作的验证?感谢您和我一起思考!