为什么 :notice 在 Rails 3 中重定向后没有显示 [英] Why is :notice not showing after redirect in Rails 3

查看:38
本文介绍了为什么 :notice 在 Rails 3 中重定向后没有显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的控制器中有以下代码

 def 创建@tv_show = TvShow.new(params[:tv_show])response_to do |格式|如果@tv_show.saveformat.html { redirect_to(tv_shows_path, :notice => '电视节目创建成功.') }format.xml { 渲染:xml =>@tv_show, :status =>:created, :location =>@电视节目 }别的format.html { 渲染:动作 =>新的" }format.xml { 渲染:xml =>@tv_show.errors, :status =>:unprocessable_entity }结尾结尾结尾

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

<%= notice %>

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

解决方案

代码不工作的原因是我的身份验证代码有问题...从头开始实现我的新身份验证方式后,上面的代码是工作.

I have the following code in my controller

  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

and the following in my tv_shows/index.html.erb

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

but when I create a new entry the notice message does not appear after the redirect to tv_shows_path. Have anyone an idea why?

解决方案

The reason why the code didn't work was a problem with my authentication code... After I implemented my new way of authentication from scratch the code above is working.

这篇关于为什么 :notice 在 Rails 3 中重定向后没有显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆