hzamani / acts_as_relation

Multi table Inheritance for rails
http://hzamani.github.com/acts_as_relation/
MIT License
180 stars 58 forks source link

Rails 4 + ActiveAdmin compatibility (Migration error) #71

Closed CrisSoFresh closed 10 years ago

CrisSoFresh commented 10 years ago

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

binhngoc17 commented 10 years ago

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

hzamani commented 10 years ago

@BattleBrisket comment on #59 is complete

zpieslak commented 10 years ago

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.

railsfactory-krishnaveni commented 9 years ago

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

wonderer007 commented 9 years ago

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

kvokka commented 8 years ago

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 7 years ago

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

ActiveAdmin.routes(self) rescue ActiveAdmin::DatabaseHitDuringLoad

This fixes the issue.

dpmango commented 7 years ago

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

estelleqiu commented 7 years ago

I find proc{} is work for me.

gabrieljoelc commented 7 years ago

I ended up converting the scope to a class method as suggested in https://github.com/hzamani/acts_as_relation/issues/71#issuecomment-207807292, 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 }
pablosistemas commented 5 years ago

rescue ActiveAdmin::DatabaseHitDuringLoad

It worked for me too!

salmagomaa commented 5 years ago

https://github.com/hzamani/acts_as_relation/issues/71#issuecomment-288430882

Thank you!