Active Admin - flash messages not appearing on page

17,077

There seems to be some issue that I haven't tracked down yet, but if you are looking for a work-around until then, this is what I did:

member_action :test do
  flash[:notice] = "This is a test notice!"
  redirect_to :action => :index
end

The problem that I am seeing is that when you put :notice in the redirect_to method, the notice message is url encoded and added to the URL

member_action :test do
  redirect_to :action => :index, :notice => "This is a test notice!"
end

results in

/admin/model?notice=This+is+a+test+notice!

which is less than ideal. I noticed a change to the active_admin documentation that includes putting {} around the first parameter to redirect_to to fix this problem, however, for me, this results in an error.

member_action :test do
  redirect_to {:action => :index}, :notice => "This is a test notice!"
end

which results in

syntax error, unexpected tASSOC, expecting '}'
    redirect_to {:action => :index}, :notice => "This...

I posted a comment on that particular pull request @ active_admin on github and hopefully someone might have another suggestion, since I am stumped.

In any event, maybe one of these solutions will work for you. Good luck.

Share:
17,077

Related videos on Youtube

Alex
Author by

Alex

Updated on June 04, 2022

Comments

  • Alex
    Alex almost 2 years

    I am trying to display a notice after redirecting to a page but it doesnt appear.

    Here is the redirect -

    redirect_to :action => :index, :notice => "My redirect"
    

    You can see the message in the url but there doesnt seem to be any code inside active admin to display it.

    Any ideas how to render it inside active admin ?

    • Cygnusx1
      Cygnusx1 over 12 years
      do you have a : <%=flash[:notice] %> in your view?
    • Alex
      Alex over 12 years
      Active admin generates the views so I dont know.
  • Alex
    Alex over 12 years
    I have added them to my layout but I want to show a flash message on a view created by active admin
  • sorens
    sorens over 12 years
    the output you reference above is from the devise install portion of the active_admin install. in other words, devise is recommending that you update your layouts to include a notice/alert fields. this is has nothing to do with how active_admin displays its notice/alert messages.
  • jevy
    jevy over 12 years
    flash[:notice] work around worked for me. I had spent an hour messing with this until I found this answer.
  • chrpes
    chrpes almost 11 years
    You're having trouble with the ruby syntax. Try to add brackets: redirect_to({action: :index}, notice: 'Whatever')
  • SexxLuthor
    SexxLuthor almost 8 years
    Using flash[:notice] in the member action didn't work correctly for me (wouldn't go away), but the above solution from @chrpes did.