2015-10-20 86 views
1

有没有人在ActiveAdmin的自定义页面中成功实施flash.now[:notice]警报?Rails&ActiveAdmin - 自定义页面上的flash.now

我正在使用使用ActiveAdmin.register_page "CustomPage"创建的自定义页面。

flash[:notice]工作,但我不能使用它,因为我没有使用redirect_to,所以警报显示在不正确的页面上。

我的Gemfile包含gem 'activeadmin', github: 'activeadmin'

应用程序/管理/ test.rb

ActiveAdmin.register_page "Test" do 
    content do 
    flash.now[:notice] = 'Test' 
    end 
end 
+0

你可以发布更多的自定义页面以供参考吗?已添加 –

+0

自定义页面。谢谢。 – kayatela

回答

2

设置flash.now[:notice]content块来不及为它进行评估并呈现为自定义页面的一部分。相反,你可以在控制器中的before_action设置闪光灯消息:

ActiveAdmin.register_page "Test" do 
    content do 
    # Test content 
    end 

    controller do 
    before_action :set_notice, only: :index 

    private 

    def set_notice 
     flash.now[:notice] = 'Test' 
    end 
    end 
end 

见动作控制器概述指南的filters节更详细的before_action

相关问题