Has anyone had success implementing flash.now[:notice] alerts within a custom page in ActiveAdmin?
I am using a custom page created with ActiveAdmin.register_page "CustomPage".
flash[:notice] works, but I cannot use it because I am not using redirect_to so the alerts show on the incorrect page.
My Gemfile contains gem 'activeadmin', github: 'activeadmin'
app/admin/test.rb
ActiveAdmin.register_page "Test" do
content do
flash.now[:notice] = 'Test'
end
end
Setting the flash.now[:notice] inside the content block is too late for it to be evaluated and rendered as part of the custom page. Instead you can set the flash message in a before_action in the controller:
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
See the filters section of the Action Controller Overview guide for more detail on before_action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With