1

我在 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
4

2 回答 2

3

在其文档中查看响应者。

于 2010-05-13T08:11:46.203 回答
2
success.html {flash[:notice] = "Hurray!"; redirect_to(@article)}}

failure.html do 
  flash[:notice] = "All bad..."
  render :action => "show"
end

只有两种方法。

于 2010-05-13T08:23:46.820 回答