redirect_to没有填充flash

时间:2014-06-23 14:52:11

标签: ruby-on-rails

我有这两种方法:

def set_asset
    @asset = current_user.assets.find(params[:id])

    rescue ActiveRecord::RecordNotFound
        redirect_to assets_url, notice: 'resource does not exist'
end

def get
    send_file @asset.uploaded_file.path, type: @asset.uploaded_file_content_type

    rescue ActionController::MissingFile
        redirect_to assets_url, notice: 'missing file'
end

如果发生MissingFile或RecordNotFound,这些方法中的急救块会成功重定向到assets_url路径。但是,没有设置闪光灯(我已调试过它)!

为什么会发生这种情况。我尝试过flash.now [:notice] =并且它也不起作用(即使只在渲染不同的视图时才使用)...

更新

现在,这是我的所有资产/ index.html.haml视图包含:

= debug flash

而且它一直是空的

1 个答案:

答案 0 :(得分:1)

Controller.rb

flash[:notice] = "resource does not exist"

查看

-flash.each do |name, msg|
  = label_tag msg