-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"config.model" raises "table doesn't exist" exception if database is dropped #289
Comments
Thanks for the bug report. This needs to be fixed before we officially release RailsAdmin as a gem. |
Agreed, the workaround I proposed does not work in all situations either. Competition is always defined, and soon as it is inspected the 'no table' exception is raised. The other workaround I have tried is wrapping the config.model block in an rescue and silently ignoring the exception. Maybe this could be done internally, rescue just the exception in question, and log to the database. |
If it helps, here's the way I'm working around it:
|
Yes, but even if the table exists, if you add columns and define them in a single push to a site like Heroku, you will still have problems when you try to run the rake task to migrate. For example, I added a :body field to a table and put in the rails admin config to have that field show the ckeditor. After pushing to Heroku, I was unable to run the rake task because it would fail on the rails admin config since the field didn't exist yet that rails admin was trying to configure. |
This workaround does not work for me (same error: table does not exist during migration):
It does seem to work with:
ruby 1.9.2 |
works for me.
does not. ruby 1.9.2 This is a serious showstopper :) |
Would it be a sensible solution to move from using an initializer to an active record class method for model specific configuration such as: in
In that case the Competition model wouldn't get loaded due to RailsAdmin, right? |
@kaapa 👍 Sounds good to me. :) |
👍 I second that. Is it possible to make it work with class reload to true? |
@bbenezech: I've added a configuration reset on Railtie |
It's perfect! |
Looks good. Is it possible to have multiple The advantage to this is that it would let us use modules to mixin admin behaviour. |
Why was this reverted? |
duplicate |
Hi, Even with a Any similar gem that uses some sort of model configuration unrelated to the database on it's initialization can face this same issue. What do you guys think about patching |
I think that is a fine solution, generally you will know the table does not exist anyway, as you'll run into this issue running a migration. |
There is a workaround here: To do not run the initializer on rake tasks. |
I have a solution that suppresses the RailsAdmin initializer during rake tasks. I modified my rails_admin.rb initializer as follows: FROM:
TO:
Note that rails generate would still get caught in this, but I figure so long as you can migrate, those issues should probably not be as big of a deal. |
Works perfectly, much thanks ! |
initializers/rails_admin.rb
then
In fact any rake task (which loads the environment) whic is run after dropping the database fails. This would appear to be because "config.model" needs to call Competition, I assume to get a list of database fields, and because the competitions table does not exist ActiveRecord raises an exception.
The solution I am using so far is to wrap the config.model block like so:
Ruby 1.9.2
Rails 3.0.3
rails_admin HEAD
The text was updated successfully, but these errors were encountered: