如何使用Inherited Resources Rails插件基于成功或失败自定义Flash消息?

我在2.3.5 Rails应用程序中使用inheritance的资源插件,并且想知道如何根据我的创建和更新操作中的成功或失败来更改flash [:notice](或任何其他flash)。

因此,如下所示,如果成功,我如何添加flash [:notice] =“All good”…如果失败,闪存[:notice] =“All bad”?

谢谢

class ArticleController  [:create, :update] def create #init new game @article = Article.new set_article_attributes_from_app @article.is_published = params[:article_publish_to_web] || false @ article.game_source = @client_application create! do |success, failure| success.html {redirect_to(@article)} success.json {render :json => {:id=>@article.id, :created_at=>@article.created_at, :picture_urls=> @article.assets.map { |a| root_url.chop + a.photo.url}}} failure.html {render :action => "show"} failure.json {render :json=>@article.errors, :status => :unprocessable_entity} end end 

 success.html {flash[:notice] = "Hurray!"; redirect_to(@article)}} failure.html do flash[:notice] = "All bad..." render :action => "show" end 

只有两种方法。

看看响应者的文档。