Skip to content
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

Weird bug with db:migrate #55

Closed
elfassy opened this issue Apr 20, 2011 · 4 comments
Closed

Weird bug with db:migrate #55

elfassy opened this issue Apr 20, 2011 · 4 comments

Comments

@elfassy
Copy link

elfassy commented Apr 20, 2011

If in my users model I have:

acts_as_audited :except => [:firstname, :lastname, :email]

I can rollback and db:migrate no problem. BUT if i have

acts_as_audited :only => [:firstname, :lastname, :email]

I get
Could not find table 'users'
(when building from scratch).
It seems like there is a problem with the :only option.... I guess i should mention that i am also using the devise gem.
Thanks!

@tyraeltong
Copy link

I'm having the same issue. I've tested several scenarios, seems this issue will happen only when using :only with devise gem.

@tyraeltong
Copy link

More information after a bit of research: It's caused by the
devise_for :users
that devise added to the routes.rb.
rake tasks will load rails environment first which in turn load the all the route definitions from routes.rb, and because of devise_for :users, devise will call it's add_mapping method and eventually use your User model definition. This triggered the acts_as_audited call, and in that call, if you have :only option set, it'll check model's table column_names, but at this time the table doesn't exists yet, thus here comes the issue.

So one work around would be comment out the devise_for :users in your routes file before you do db migration from scratch and then uncomment it. This is ugly but still have no idea how to fix it.

@fdeschenes
Copy link

This is a really old issue, which unfortunately is still unresolved as of 4.2. Rather than commenting code out, I solved the issue this way:

class User < ActiveRecord::Base
  audited if self.table_exists?

  ...
end

If/when I have more time, I'll look into adding a check and submitting a pull request.

@laserlemon
Copy link
Contributor

@fdeschenes Thank you for the workaround. Yes, please submit a PR (if you haven't already). Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants