Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 978
mwoods79 Avatar asked Dec 04 '12 04:12

mwoods79


1 Answers

Like this:

::User.find(user_id)
like image 184
Chris Salzberg Avatar answered Nov 13 '22 13:11

Chris Salzberg