无法从其他方法输出flash msg

时间:2012-12-28 00:40:00

标签: ruby-on-rails ruby-on-rails-3

我尝试使用其他功能/方法重定向&输出通知,但它不起作用。它在自己的功能中工作正常。

  def delete_sb
    # @sb = SasaranBaru.find(params[:id])
    # @sb.destroy
    flash[:notice] = "fffff"
    render_group("flash msg")
  end

  def render_group(notice)
    logger.debug notice
    flash[:notice] = notice
    if params[:filter]
      filter = prepare_filter_query(params[:filter])
      redirect_to "/groups?#{filter.to_query}", notice: 'okokoko okokokok '
    else
      redirect_to "/groups", notice: 'hehehehe eheheheh'
    end
  end

在我看来,flash没有任何价值。

1 个答案:

答案 0 :(得分:1)

此代码后是否有重定向?闪存仅对一个请求有效,然后消失。

测试这个的一种方法是使用:

flash.keep[:notice]='ffffff'

并查看是否显示,但我怀疑您正在通过/group中的另一个控制器并再次重定向,丢失了闪存。