0
我目前正试图在每次自定义方法(process!)在我的事务控制器中返回false或true时显示消息。但是,每一次错误只返回一次,每一次错误只返回一次。下面是在控制器代码:循环中的Flash消息将不会显示多次
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>
我假设,因为我只是在应用程序布局一次提到它的代码(一个出错,一个成功),它只显示一次。我想知道如何让它显示由“process!”方法返回的每个false。
在此先感谢。
有道理和阵列工作。谢谢! – Alex