Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active Admin - flash messages not appearing on page

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 ?

like image 824
Alex Avatar asked Oct 27 '11 14:10

Alex


People also ask

Where are flash messages stored?

They are stored in your session store. The default since rails 2.0 is the cookie store, but check in config/initializers/session_store.

How do I use Active Admin?

Run the generator to install Active Admin. This will create an AdminUser model, an initializer file for configuring Active Admin and an app/admin directory that will hold the administration files. It uses Devise for authentication.

What is active admin?

Active Admin is a framework for creating administration style interfaces. It abstracts common business application patterns to make it simple for developers to implement beautiful and elegant interfaces with very little effort.


1 Answers

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.

like image 99
sorens Avatar answered Sep 18 '22 19:09

sorens