I have following problem, which I don't understand: I have an User model:
class User < ActiveRecord::Base
...
private
def generate_token(column)
begin
self[column] = SecureRandom.urlsafe_base64
end while User.exists?(column => self[column])
end
end
and an integration test:
it "should sign an user in" do
user = FactoryGirl.create(:user)
visit root_path
click_link "Sign in"
fill_in :email, with: user.email
fill_in :password, with: user.password
click_button
controller.should be_signed_in
click_link "Sign out"
controller.should_not be_signed_in
end
which fails on
User.exists?
with
NameError uninitialized constant User::User
replacing mentioned row with
self.class.exists?
fixes it.. Can someone please lead me out of confusion? :) thanks in advance..
Looks like that method is running inside a scope namespaced with User, maybe you are defining it through a module (just guessing). By the way, you can write as following:
::User.exists?
And it should start the "namespace resolving" from root.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.