Last active
August 29, 2015 13:57
-
-
Save olivierlacan/9548055 to your computer and use it in GitHub Desktop.
Trying to figure out why I'm having to manually require a class that is within the same namespace inside of Rails.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# located in lib/pumper/nickel.rb | |
# the only way Back.setup works inside of #add_crappy_music | |
# is if I add the following: | |
# require "pumper/nickel/back" | |
# | |
# Why? | |
module Pumper | |
class Nickel < ActiveRecord::Base | |
def add_crappy_music | |
# called within a different class in a different namespace | |
# this call causes undefined method `setup' for Back:Class | |
Back.setup | |
# does not work when calling Pumper::Nickel::Back.setup either | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Pumper | |
class Nickel < ActiveRecord::Base | |
class Back < ActiveRecord::Base | |
def setup | |
puts "whining" | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# located in app/services/thing/back_creator.rb | |
module Thing | |
class BackCreator | |
def run | |
nickel = Pumper::Nickel.new | |
nickel.add_crappy_music # the failing call originates here | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# located in app/models/iron.rb | |
class Iron < ActiveRecord::Base | |
# irrelevant | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Before anybody asks,
/lib
is in myconfig.autoload_paths
.