在我的Rails3应用程序中,我在Model1中有一个方法,在更新Model1并满足某些条件时创建其他对象。所以我在Model1中有一个after_update回调方法来完成这项工作。我想将消息传回控制器以显示在页面上,但模型中没有闪存。
这样做的正确方法是什么?
答案 0 :(得分:1)
如果您的Thing模型具有常规旧attr_accessor :messages
,那么您的控制器可以执行此操作:
def update
@thing = Thing.find params[:id]
if @thing.update_attributes
redirect_to root_path, :notice => "The messages are #{@thing.messages}"
else
render 'edit'
end
end
消息不会随@thing
一起保存,但没关系,他们只需要足够长的时间进入下一行的Flash通知。