1

2.3.5 Railsアプリケーションで継承されたリソースプラグインを使用していて、作成および更新アクションの成功または失敗に基づいてflash [:notice](またはその他のフラッシュ)を変更する方法を考えていました。

したがって、以下の場合、成功した場合は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

それを行うための2つの方法。

于 2010-05-13T08:23:46.820 に答える