I have a model called User
. I have pluralize_table_names
set to false so the table User
uses is user
. (That's kind of a mouthful!)
Interestingly, my model behaves correctly in development but in production User
tries to use a table called users
which doesn't exist. All my other models use their singular table names. Look at this:
$ rails console
Loading development environment (Rails 3.0.3)
irb(main):001:0> Client.table_name
=> "client"
irb(main):002:0> Appointment.table_name
=> "appointment"
irb(main):003:0> User.table_name
=> "user"
irb(main):004:0>
$ rails console production
Loading production environment (Rails 3.0.3)
irb(main):001:0>开发者_如何学C Client.table_name
=> "client"
irb(main):002:0> Appointment.table_name
=> "appointment"
irb(main):003:0> User.table_name
=> "users"
irb(main):004:0>
As you can see, everything's fine except User
in production. What gives?
Edit: here's the model code in production:
class User < ActiveRecord::Base
acts_as_authentic
end
And in development:
class User < ActiveRecord::Base
acts_as_authentic
end
Same exact thing. I even pointed my production instance at the same database as development and the problem persists. I started having these problems when I started using Authlogic, so I'm starting to suspect that the development environment somehow knows about some Authlogic stuff that the production environment doesn't.
Update: I tried to kill as many moving parts as possible. I set both my production environment and my development environment to point at the dev database. That didn't change anything. I changed my production environment to be a dev one and it started working. I changed my dev environment to a production one and it stopped working. This tells me there's something about the change from dev to production that makes it stop working. I have no idea what, though.
I figured it out. I ended up keeping the singular user
table name in the database, but in my model, I did this:
class User < ActiveRecord::Base
set_table_name "user"
acts_as_authentic
end
The directives have to be in that order or else it will not work! I don't know why that's the case (actually, if I think about it a little bit, it makes sense) and I don't know why I decided to try to switch the order but I'm glad I did.
精彩评论