mwoods79
mwoods79

Reputation: 1648

Use an object from outside your modules scope

I have code like this.

class User < ActiveRecord::Base
end

module Foo
  class User
  end
end

module Foo
  class DoesSomethingWithActiveRecordUser
    def initialize user_id
      User.find(user_id)
    end
  end
end

If I call Foo::DoesSomethingWithActiveRecordUser.new(1) I get an error message that says something like undefined method 'find' for Foo::User.

How do I call the ActiveRecord User from within Foo?

Thanks.

Upvotes: 9

Views: 3955

Answers (1)

Chris Salzberg
Chris Salzberg

Reputation: 27374

Like this:

::User.find(user_id)

Upvotes: 30

Related Questions