Active Admin - flash messages not appearing on page

Alex picture Alex · Oct 27, 2011 · Viewed 14.8k times · Source

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 ?

Answer

sorens picture sorens · Nov 17, 2011

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.