flash[:notice] 不适用于 redirect_to [英] flash[:notice] doesn't work with redirect_to

查看:38
本文介绍了flash[:notice] 不适用于 redirect_to的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用控制器状态:

 flash[:notice] = 'message'重定向到(控制器:'项目',动作:'列表')

我不知道为什么通知没有出现.

我尝试并检查了很多东西:

  1. flash.keep
  2. flash.keep[:notice] = 'message'
  3. flash[:notice]render
  4. 配合良好
  5. redirect_to(controller: 'item', action: 'list', notice: 'message')
  6. flash.now[:notice] = "Hello world"
  7. flash.now['foo'] = "Hello world" 带有 <%= flash['foo'] %> 在视图中
  8. 布局中有一个 <%= flash[:notice] %>

我将以下代码放入布局中.当我的控制器方法有一个同名的视图时,flash[:notice] 工作正常.当我尝试访问另一个没有视图的控制器时会出现问题.

<% if !flash[:notice].blank?%><div class="通知"><%= flash[:notice]%>

<%结束%><% if !flash[:alert].blank?%><div class="alert"><%= flash[:alert]%>

<%结束%>

有人可以帮忙吗?

信息:

  • Ruby (2.0.0)
  • Rails (3.2.13)

解决方案

我不知道发生了什么.

我更新到 ruby​​ 2.0.0,它又开始工作了...

I'm using from controller status:

  flash[:notice] = 'message'
  redirect_to(controller: 'item', action: 'list')

I don't know why the notice don't show up.

I tried and checked many things:

  1. flash.keep
  2. flash.keep[:notice] = 'message'
  3. flash[:notice] works fine with render
  4. redirect_to(controller: 'item', action: 'list', notice: 'message')
  5. flash.now[:notice] = "Hello world"
  6. flash.now['foo'] = "Hello world" with <%= flash['foo'] %> in the view
  7. There is a <%= flash[:notice] %> in the layout

I put the following code to in the layout. flash[:notice] work fine when I the controller method have a view with the same name. The problem happens when I try to reach another controller which don't have a view.

<% if !flash[:notice].blank? %>
    <div class="notice">
        <%= flash[:notice] %>
    </div>
<% end %>

<% if !flash[:alert].blank? %>
    <div class="alert">
        <%= flash[:alert] %>
    </div>
<% end %>   

Can anyone help?

Info:

  • Ruby (2.0.0)
  • Rails (3.2.13)

解决方案

I have no idea about what happened.

I updated to ruby 2.0.0 and it just started to work again...

这篇关于flash[:notice] 不适用于 redirect_to的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆