# Problem accessing mixin module methods from views

**URL:** <https://www.ruby-forum.com/t/problem-accessing-mixin-module-methods-from-views/113196>\
**Category:** Rails\
**Created:** [August 28, 2007, 4:58pm UTC](https://www.ruby-forum.com/t/problem-accessing-mixin-module-methods-from-views/113196 "2007-08-28T16:58:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yardboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/9de0a6/32.png) [@yardboy](https://www.ruby-forum.com/u/yardboy)\
**Post date:** [August 28, 2007, 4:58pm UTC](https://www.ruby-forum.com/t/problem-accessing-mixin-module-methods-from-views/113196/1 "2007-08-28T16:58:49Z")

</div>

I’m trying to write a module to be used as a mix-in, my first attempt at  
such. This sample code outlines the basics of what I’ve done so far…

/lib/foo.rb:  
require ‘foo/base’  
module Foo  
include FooBase  
end

/lib/foo/base.rb:  
module Foo  
module FooBase  
def foo\_var  
123  
end  
end  
end

/app/controllers/application.rb

# Filters added to this controller apply to all controllers in the

application.

# Likewise, all the methods added will be available for all controllers.

require ‘foo’  
class ApplicationController \< ActionController::Base  
include Foo  
end

Given these three files, I can use “foo\_var” without error in any of my  
controllers. However, when I try to use “foo\_var” in a view, I get a “no  
method” error. I know it’s possible to make “foo\_var” available  
everywhere - example, the login engine had “current\_user” and “user?”  
methods that could be accessed in any controller or view.

I’m sort of shooting in the dim light, not quite the dark, after reading  
some articles and sample code. Any help appreciated.

thanks.

---

<div class="post-metadata">

**Author:** ![yardboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/9de0a6/32.png) [@yardboy](https://www.ruby-forum.com/u/yardboy)\
**Post date:** [August 30, 2007, 6:15pm UTC](https://www.ruby-forum.com/t/problem-accessing-mixin-module-methods-from-views/113196/2 "2007-08-30T18:15:52Z")

</div>

Hai cayce,

Once you include a module say Foo, only methods from Foo will be mixed  
to the included class.  
But i am not sure whether the nested module’s will also get mixed to  
the included class. If yes, not sure how to access those methods.

But in your example if you add  
require ‘foobase’  
class ApplicationController \< ActionController::Base  
include Foo  
include FooBase

end

now if you say

ApplicationController.new.foo\_var, surely it will work.

On Aug 28, 7:58 pm, Cayce B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![yardboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/9de0a6/32.png) [@yardboy](https://www.ruby-forum.com/u/yardboy)\
**Post date:** [August 31, 2007, 8:37pm UTC](https://www.ruby-forum.com/t/problem-accessing-mixin-module-methods-from-views/113196/3 "2007-08-31T20:37:29Z")

</div>

Thanks I’ll give that a shot.

c.

raghukumar wrote:

> Hai cayce,
> 
> Once you include a module say Foo, only methods from Foo will be mixed  
> to the included class.  
> But i am not sure whether the nested module’s will also get mixed to  
> the included class. If yes, not sure how to access those methods.
> 
> But in your example if you add  
> require ‘foobase’  
> class ApplicationController \< ActionController::Base  
> include Foo  
> include FooBase
> 
> end
> 
> now if you say
> 
> ApplicationController.new.foo\_var, surely it will work.
> 
> On Aug 28, 7:58 pm, Cayce B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
