hzamani/acts_as_relation

Rails 4 + ActiveAdmin compatibility (Migration error)

Closed this issue ยท 12 comments

Hi, I've a Rail 4 project with ActiveAdmin and emerged a little problem with migrations. This project have a typical AdminUser model but this time with a Receptionist inherit from AdminUser, so my acts_as method looks like acts_as :admin_user. This works fine in runtime but when run rake db:drop, rake db:create',rake db:migrate`, etc I get some circular reference problem as I see in other previous issues (calling the AdminUser table), but this time I get a standard ActiveAdmin error :

ActiveAdmin::DatabaseHitDuringLoad: Your file, app/models/receptionist.rb (line 3),
caused a database error while Active Admin was loading. This is most common when
your database is missing or doesn't have the latest migrations applied. To prevent this
error, move the code to a place where it will only be run when a page is rendered.
Original error message: PG::UndefinedTable: ERROR:  relation "admin_users" does 
not exist

Searching a little I found this : https://github.com/gregbell/active_admin/blob/master/lib/active_admin/error.rb

Then to try to solve (provisionally) the problem, I use this : acts_as :admin_user if connection.table_exists? 'admin_users' in my Receptionist class.

This works fine, but clearly it is a very dirty solution. Have any ideas to improve it or make it more elegant?
(thinking that you can probably add more models inheriting from AdminUser).

Thanks in advance

I am getting the same error... and I although I have added the acts-as but it still cannot resolve the problem

@BattleBrisket comment on #59 is complete

I had the same issue on the newest master branch (activeadmin/activeadmin/commit/930d34cd224272687613dcf1db4cf5b1347f1098) of active_admin. The thing that caused it, was custom 'filter' options which were not wrapped in proc objects.

Filter part can be changed like this to avoid getting this kind of errors.


ActiveAdmin.register Table do

begin
filter: id
filter: name
rescue
p "msg"
end

end

I was also getting same error on rake db:migrate. I just commented that line and rake db:migrate runs perfectly and comment it after

Got the same error.
helped moving in models form scope :foo -> {bar} to def self.foo bar;end for table loading for avoid error

r-a-o commented

Replace ActiveAdmin.routes(self) with below line in routes.rb

ActiveAdmin.routes(self) rescue ActiveAdmin::DatabaseHitDuringLoad

This fixes the issue.

@r-a-o It works for me also. Thanks

I find proc{} is work for me.

I ended up converting the scope to a class method as suggested in #71 (comment), but only after trying to figure out what using a proc means for custom filters. @estelleqiu and @zpieslak are you referring to setting the collection option as in the following (see docs):

filter :author, collection: proc { Author.all }

rescue ActiveAdmin::DatabaseHitDuringLoad

It worked for me too!