Ruby on rails 如何使用继承的资源Rails插件根据成功或失败定制flash消息?
我正在2.3.5 Rails应用程序中使用继承资源插件,并想知道如何根据创建和更新操作中的成功或失败来更改flash[:注意](或任何其他flash) 因此,鉴于以下情况,如果成功,我如何添加flash[:notice]=“一切都好”。。。而flash[:注意]=如果失败,则为“全坏” 谢谢Ruby on rails 如何使用继承的资源Rails插件根据成功或失败定制flash消息?,ruby-on-rails,ruby,resources,ruby-on-rails-plugins,inherited,Ruby On Rails,Ruby,Resources,Ruby On Rails Plugins,Inherited,我正在2.3.5 Rails应用程序中使用继承资源插件,并想知道如何根据创建和更新操作中的成功或失败来更改flash[:注意](或任何其他flash) 因此,鉴于以下情况,如果成功,我如何添加flash[:notice]=“一切都好”。。。而flash[:注意]=如果失败,则为“全坏” 谢谢 class ArticleController < InheritedResources::Base actions :show, :create, :update respond_to :
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
class ArticleController[:create,:update]
def创建
#初始化新游戏
@article=article.new
从应用程序设置文章属性
@article.is_published=params[:article_publish_to_web]| false
@article.game\u source=@client\u应用程序
创造!成功、失败|
success.html{redirect_to(@article)}
success.json{render:json=>{:id=>@article.id,:created_at=>@article.created_at,:picture_url=>@article.assets.map{| a | root_url.chop+a.photo.url}}
failure.html{render:action=>“show”}
failure.json{render:json=>@article.errors,:status=>:unprocessable_entity}
结束
结束
查看其文档。查看其文档
success.html {flash[:notice] = "Hurray!"; redirect_to(@article)}}
failure.html do
flash[:notice] = "All bad..."
render :action => "show"
end
只有两种方法
只有两种方法