我在 2.3.5 Rails 应用程序中使用继承的资源插件,想知道如何根据创建和更新操作的成功或失败更改 flash[:notice](或任何其他 flash)。
鉴于以下情况,如果成功,我该如何添加 flash[:notice] = "All good"... 如果失败,如何添加 flash[:notice] = "All bad"?
谢谢
class ArticleController < InheritedResources::Base
actions :show, :create, :update
respond_to :html, :json
before_filter :authorize_upsert, :only => [: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
最佳答案
看看responders在其文档中。
关于ruby-on-rails - 如何使用 Inherited Resources Rails 插件根据成功或失败自定义 flash 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2824271/