現在、カスタムメソッド(プロセス!)がトランザクションコントローラー内でfalseまたはtrueを返すたびにメッセージを表示しようとしています。ただし、falseごとに1回、trueごとに1回だけ返されます。以下は、コントローラーのコードです。
def execute_all
@transaction = Transaction.find(:all)
#Execute all transactions
@transaction.each do |t|
if (t.process!)
#flash.keep[:noticeTransaction] = 'Transaction number: ' + t.id.to_s + ' executed Successfully!'
else
flash.keep[:errorTransaction] = 'Transaction cannot be executed -> Transaction Id: ' + t.id.to_s
end
end
respond_to do |format|
format.html { redirect_to transactions_url }
format.json { head :no_content }
end
以下は、application.html.erbのコードです。
<html>
<head>
</head>
<body>
<p style="color:red" class="error"><%= flash[:errorTransaction] %></p>
<p style="color:green" ><%= flash[:noticeTransaction] %></p>
<%= yield %>
</body>
アプリケーションレイアウトで一度だけ言及しているので(1つはエラー用、もう1つは成功用)、1回だけ表示されると思います。メソッド「process!」によって返されるfalseごとにどのように表示するのでしょうか。
前もって感謝します。