Unable to include mixins with Rails 1.2 update


I’m in the process of updating from 1.1.6 to 1.2.1. Fixed deprecated
stuff, but this one I’m kinda stuck with. I have an application
controller that is unable to include a mixin. The dependencies.rb in
active support bails with this core message:

load_missing_constant': Mail is not missing constant MailSidebar! (ArgumentError) from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active_support/dependencies.rb:453:inconst_missing’

The Controller in this case starts with this:
class Mail::MailTypeController < ApplicationController
include MailSidebar
def index
render :action => ‘list’

And the sidebar is just this:
module Mail::MailSidebar
“Mail Events”=> {:controller => “/mail/sendmail_event”, :action
=> “list”},
“Mail Templates”=> {:controller => “/mail/mail_template”, :action
=> “list”},
“Mail Types”=> {:controller => “/mail/mail_type”, :action =>
def sidebar?
def sidebar_links

Any thoughts on where to look? Of course, it works fine with Rails
1.1.6. I’ve also noticed a problem where if I comment out all the
includes, and run the application, my application_helper methods only
work with the first page load, going to any page after the first one
for the controller fails until I restart the server. I think there is
a problem with something in my environment and mixins, as the
application helper is just another module that is ‘mixed in’.

Thanks for any help people can offer.

Okay, I ended up solving the first problem by simply using the
namespace of the mixin, so the include now looks like this:

include Mail::MailSidebar

which fixed my test cases. Now, I still have the second problem I
mentioned, which still may be related, but I’m not sure how, or even
what to show to ask for help. The issue is I have an application
helper that makes a set of calls to an object-graph that consists of
three different classes. I get the following exception:
undefined method `get_locale_strings’ for #Brand:0xb7922824
which does exist in the Brand class itself. (Remember, first time
loading the page this does not happen, only each time after the first)
The stack-trace looks like this:

method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/associations/association_proxy.rb:123:inmethod_missing’
app/models/organizational_unit.rb:103:in create_locale_strings' app/models/brand_maintainer.rb:66:inget_locale_strings’
app/models/brand_maintainer.rb:54:in get_locale_strings_by_user_id' app/models/brand_maintainer.rb:193:inget_user_locale’
app/models/brand_maintainer.rb:108:in search_for_locale_string' app/helpers/application_helper.rb:27:inlocale’

Which is kinda weird to me only that the stack trace doesn’t include
the Brand class itself, but that may be not relevant… I’m not sure
how the stack propagates with the missing_method. Now, in the class
structure, BrandMaintainer is a singleton, OrganizationalUnit contains
a single brand… and the brand maintainer is manipulating the OU
above. Specifically, in the method where the failure occurs, the
following is called:

hash = brand.get_locale_strings(lang)

and Brand does have in the brand.rb file, a method called:
def get_locale_strings(lang=nil)

and I can see it called the first time though, but fails on each
existing one. Any ideas on where to look for the bug in my code?
(Again, this worked in Rails 1.1.6, and I see the problem with Rails

One more thing, then I’ll wait for someone else to respond with an idea
on the problem…

If I set to cache my classes in config/development.rb, then I don’t get
the problem described above.
config.cache_classes = true
I’m trying to come up with a small test case to show it now.

Okay, got the fix, figure I’d post this incase anyone else runs into
the same problem.

Turns out this issue is directly related to the fact that rails doesn’t
‘preload’ in Rails 1.2.1 like it did with Rails 1.1.6… and the
problem I had was really isolated to a singleton class, my
BrandMaintainer, when it used objects that tried to load other objects.
Once I added in the ‘require’ tags for each model object it needed, it
seems to work fine.

I’ll be doing more tests and if I find anything else about this, I’ll
post it too.