# Unable to include mixins with Rails 1.2 update

**URL:** <https://www.ruby-forum.com/t/unable-to-include-mixins-with-rails-1-2-update/82687>\
**Category:** Rails\
**Created:** [January 19, 2007, 6:31pm UTC](https://www.ruby-forum.com/t/unable-to-include-mixins-with-rails-1-2-update/82687 "2007-01-19T18:31:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ned\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@Ned\_W](https://www.ruby-forum.com/u/Ned_W)\
**Post date:** [January 19, 2007, 6:31pm UTC](https://www.ruby-forum.com/t/unable-to-include-mixins-with-rails-1-2-update/82687/1 "2007-01-19T18:31:29Z")

</div>

Folks-

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:

/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active\_support/dependencies.rb:241:in  
`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:in`const\_missing’  
from  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.0/lib/active\_support/dependencies.rb:471:in  
`const\_missing’  
from  
/home/nwolpert/workspace/lms/config/…/app/controllers/mail/mail\_type\_controller.rb:3

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

And the sidebar is just this:  
module Mail::MailSidebar  
SIDEBAR\_LINKS = {  
“Mail Events”=\> {:controller =\> “/mail/sendmail\_event”, :action  
=\> “list”},  
“Mail Templates”=\> {:controller =\> “/mail/mail\_template”, :action  
=\> “list”},  
“Mail Types”=\> {:controller =\> “/mail/mail\_type”, :action =\>  
“list”}  
}  
def sidebar?  
true  
end  
def sidebar\_links  
SIDEBAR\_LINKS  
end  
end

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.

---

<div class="post-metadata">

**Author:** ![Ned\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@Ned\_W](https://www.ruby-forum.com/u/Ned_W)\
**Post date:** [January 19, 2007, 6:52pm UTC](https://www.ruby-forum.com/t/unable-to-include-mixins-with-rails-1-2-update/82687/2 "2007-01-19T18:52:30Z")

</div>

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:

/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active\_record/base.rb:1848:in  
`method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.1/lib/active_record/associations/association_proxy.rb:123:in`method\_missing’  
app/models/organizational\_unit.rb:103:in `create_locale_strings' app/models/brand_maintainer.rb:66:in`get\_locale\_strings’  
app/models/brand\_maintainer.rb:54:in `get_locale_strings_by_user_id' app/models/brand_maintainer.rb:193:in`get\_user\_locale’  
app/models/brand\_maintainer.rb:108:in `search_for_locale_string' app/helpers/application_helper.rb:27:in`locale’

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  
1.2.1)

---

<div class="post-metadata">

**Author:** ![Ned\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@Ned\_W](https://www.ruby-forum.com/u/Ned_W)\
**Post date:** [January 19, 2007, 7:13pm UTC](https://www.ruby-forum.com/t/unable-to-include-mixins-with-rails-1-2-update/82687/3 "2007-01-19T19:13:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ned\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/22d042/32.png) [@Ned\_W](https://www.ruby-forum.com/u/Ned_W)\
**Post date:** [January 19, 2007, 9:41pm UTC](https://www.ruby-forum.com/t/unable-to-include-mixins-with-rails-1-2-update/82687/4 "2007-01-19T21:41:00Z")

</div>

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.
