It sounds like autoloading issues. Have you tried referencing the MarketingMailer constant using the full name? ::Marketing::MarketingMailer ?
Rails doesn't load all classes in development. Instead, when a class is missing, Rails tries to guess where in the project to find the class, based on a set of autoloading paths.
For instance, all of the folders in your app folder are added to the autoloading paths. So if you reference Foobar.new, Rails will look in your app/models or app/controllers for a foobar.rb file, that it expects to contain a class Foobar
definition. However, when you use modules, the waters become more muddy.
class Foo::Bar
# some code
Baz.new
end
Rails will now think that the Baz class is defined in a baz.rb class that is located in subfolders, so it will look in the autoload folders and search for subfolders named according to the enclosing modules, checking app/models/foo/bar/baz.rb and app/controllers/foo/bar/baz.rb
When it doesn't find anything, Rails has different ways of trying to resolve it which I don't fully understand. However, if you prefix your class reference with two colons, that means you are referencing from the root namespace and Rails should not try to search relative to your current module, so if we take the above example again:
class Foo::Bar
...
Baz.new # Searches for foo/bar/baz.rb
::Baz.new # Searches for baz.rb
::My::Baz.new # Searches for my/baz.rb
My::Baz.new # Searches for foo/bar/my/baz.rb
...
end
In production mode, most of these problems disappear, because Rails preloads all source files in your project, so if Baz
has been defined anywhere in any folder, Rails doesn't have to make guesses about where to find it. It already exists, because it has been loaded.