レコードを作成中に特定のフィールドに基づいて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
とそのレコードを作成する必要がある場合は、ポップアップを表示したいと思います。それを行う方法はありますか?
ありがとうございました。
EDIT: 私はそれを次のようにすることはできますか?
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
しかし、Iamは、まだこれは本当にコントローラの問題であり、コントローラではなく、モデルで対処しなければならないNameError (undefined local variable or method 'flash' for #)
あなたがより明確にしてくださいことはできますか?フォームではどういう意味ですか? – Mounika
シンプルにしておくと、新しいアクションを作成する際に、レールモジュールにポップアップメッセージを表示する方法はありますか? – Mounika