我之前问了一个问题,引起了一些很好的反应。
根据那里给出的一些建议,我尝试移动以下控制器逻辑
if params[:concept][:consulted_legal] == 0 && params[:concept][:consulted_marketing] == 1
@concept.attributes = {:status => 'Awaiting Compliance Approval'}
elsif params[:concept][:consulted_marketing] == 0 && params[:concept][:consulted_legal] == 1
@concept.attributes = {:status => 'Awaiting Marketing Approval'}
elsif params[:concept][:consulted_marketing] == 0 && params[:concept][:consulted_legal] == 0
@concept.attributes = {:status => 'Awaiting Marketing & Legal Approval'}
else
@concept.attributes = {:status => 'Pending Approval'}
end
进入模型,如下所示:
def set_status
if status.blank?
if (consulted_legal == true) && (consulted_marketing == true)
status = "Pending Approval"
elsif (consulted_legal == true) && (consulted_marketing == false)
status = "Awaiting Marketing Approval"
elsif (consulted_legal == false) && (consulted_marketing == true)
status = "Awaiting Legal Approval"
elsif (consulted_legal == false) && (consulted_marketing == false)
status = "Awaiting Marketing & Legal Approval"
end
end
true # Needs to return true for the update to go through
end
我从 before_save 回调中调用它。
默认情况下,consulted_legal 和consulted_marketing 属性都设置为false 而不是null,这就是为什么我在这里测试== false 或true,而不是询问
if consulted_legal?
例如。
但是,这种逻辑似乎不起作用。如果我检查该对象,则永远不会将状态设置为任何内容。谁能发现为什么会发生这种情况?例如,我是否知道模型中的属性是如何被错误访问的?
TIA