ruby-on-rails-3 – 为什么:注意在Rails 3中重定向后不显示

我的控制器中有以下代码
def create
    @tv_show = TvShow.new(params[:tv_show])

    respond_to do |format|
      if @tv_show.save
        format.html { redirect_to(tv_shows_path,:notice => 'Tv show was successfully created.') }
        format.xml  { render :xml => @tv_show,:status => :created,:location => @tv_show }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @tv_show.errors,:status => :unprocessable_entity }
      end
    end
  end

和我的tv_shows / index.html.erb中的以下内容

<div id="notice"><%= notice %></div>

但是当我创建一个新条目时,通知消息不会在重定向到tv_shows_path之后出现.有没有人想到为什么?

解决方法

有什么理由你试图使用:通知而不是闪光[:通知]?

控制器:

respond_to do |format|
  if @tv_show.save
    format.html { 
      flash[:notice] = 'Tv show was successfully created.'
      redirect_to tv_shows_path 
    }
    format.xml  { render :xml => @tv_show,:location => @tv_show }
  else
    format.html { render :action => "new" }
    format.xml  { render :xml => @tv_show.errors,:status => :unprocessable_entity }
  end
end

视图:

<% if flash[:notice] %>
    <div id="notice"><%= flash[:notice] %></div>
<% end %>

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...