ruby-on-rails-3 – 为什么:注意在Rails 3中重定向后不显示
发布时间:2020-12-16 22:07:42 所属栏目:百科 来源:网络整理
导读:我的控制器中有以下代码 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,
我的控制器中有以下代码
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 %> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |