Rails3:显示来自模型的消息?

时间:2011-06-25 19:45:22

标签: ruby-on-rails-3

在我的Rails3应用程序中,我在Model1中有一个方法,在更新Model1并满足某些条件时创建其他对象。所以我在Model1中有一个after_update回调方法来完成这项工作。我想将消息传回控制器以显示在页面上,但模型中没有闪存。

这样做的正确方法是什么?

1 个答案:

答案 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通知。

相关问题