2013-02-10 81 views
-3

我創建了Posts模型,我想在模型保存或更新時更改Flash通知文本。Flash通知文本更改

我該怎麼做? 謝謝!

+0

請閱讀有關閃光燈如何在導軌中工作的信息。 http://guides.rubyonrails.org/action_controller_overview.html#the-flash&http://travisonrails.com/2008/08/17/working-with-the-flash-hash將是一個好的開始。 – 2013-02-10 16:19:20

+0

結帳https://github.com/plataformatec/responders – 2013-02-10 22:15:09

回答

1

在你的控制器動作,在那裏你調用Post方法,例如這樣做:

class FooController < ApplicationController 
    def create 
    if Post.create(params) 
     flash.notice 'Post saved' 
    else 
     flash.alert 'Post not saved' 
    end 
    end 
end 

這是最好把你的模型從控制器和控制方法,如flash隔離,並設置這些控制器代替。

+0

非常感謝! – RydelHouse 2013-02-10 16:26:33