我想在创建记录时根据特定字段显示弹出式消息/ update some other table also
。RAILS:弹出/警告/消息before_create
有没有办法使用验证或操作链接来做到这一点?
我想要做的事象下面这样:
validates :fieldc, if: :should_update?, message: "Update fielda and fieldb in tablex also"
bef should_update?
fieldc == "req_value"
end
我相信上面的验证将无法正常工作。但我想显示弹出窗口,如果fieldc == req_value
和记录应该创建。有没有办法做到这一点?
谢谢。
编辑: 我可以这样做吗?
after_create :update_tablex
def update_tablex
if self.should_update?
flash[:notice] = 'Please update fielda and fieldb in tablex also'
else
flash[:notice] = 'Record updated successfully.'
end
end
def should_update?
fieldc == "req_value"
end
但是荫仍然得到NameError (undefined local variable or method 'flash' for #)
能否请您更清楚了吗?你的形式是什么意思? – Mounika
保持简单,是否有办法在rails模块中显示弹出消息来执行创建新操作? – Mounika