Как настроить флеш-сообщение на основе успеха или неудачи с плагином Inherited Resources Rails? - PullRequest
1 голос
/ 13 мая 2010

Я использую плагин унаследованных ресурсов в приложении 2.3.5 Rails, и мне было интересно, как изменить флэш-память [: note] (или любую другую флэш-память), основываясь на успехе ИЛИ сбое в моих действиях создания и обновления.

Итак, учитывая нижеприведенное, как мне добавить flash [: note] = "Все хорошо", если успех ... и flash [: note] = "Все плохо", если сбой?

Спасибо

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

Ответы [ 2 ]

3 голосов
/ 13 мая 2010

Взгляните на респондентов в его документации.

2 голосов
/ 13 мая 2010
success.html {flash[:notice] = "Hurray!"; redirect_to(@article)}}

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

Всего два способа сделать это.

...