1

我正在尝试执行 after_save 条件回调

after_save :change_rel_status, :if => :relation_type_id == 1

def change_rel_status
  self.status = "Confirmed"
  self.save
end

但我收到错误消息undefined method after_save for false:FalseClass

{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"f4IN...=",
"relationship"=>{"relation_type_id"=>"1",
"category_ids"=>[""]},
"commit"=>"Update Relationship",
"id"=>"19"}

我不确定是不是因为表单还有其他模型的其他属性没有更新?

谢谢。

4

1 回答 1

0

我可以建议一些更简单的东西:

before_save :change_rel_status

def change_rel_status
  if params[:relationship][:relation_type_id] == 1
    self.status = "Confirmed"
  end
end
于 2012-12-07T20:00:38.010 回答