# How to include module's class in controller?

**URL:** <https://www.ruby-forum.com/t/how-to-include-modules-class-in-controller/174410>\
**Category:** Rails\
**Created:** [August 26, 2009, 3:13pm UTC](https://www.ruby-forum.com/t/how-to-include-modules-class-in-controller/174410 "2009-08-26T15:13:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [August 26, 2009, 3:13pm UTC](https://www.ruby-forum.com/t/how-to-include-modules-class-in-controller/174410/1 "2009-08-26T15:13:00Z")

</div>

Hello all,

I have a module that contains a class as following

## my\_module.rb

module MyModule

class MyClass \< OtherClass

def my\_method(value)  
#process value  
return value  
end

end

## end

In my controller

class MyController \< ApplicationController  
include MyModule::MyClass ### How to include module’s class here

def show  
@result = my\_method(value) ### How to access module’s class method  
here  
end

## end

but it throws error  
TypeError  
wrong argument type Class (expected Module)

How can I use a module’s class’s method in my controller?

Thanks,

Vikas.

---

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [August 26, 2009, 4:23pm UTC](https://www.ruby-forum.com/t/how-to-include-modules-class-in-controller/174410/2 "2009-08-26T16:23:43Z")

</div>

write the module in its helper and call it whenever you needed it

---

<div class="post-metadata">

**Author:** ![vikas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ac91a4/32.png) [@vikas](https://www.ruby-forum.com/u/vikas)\
**Post date:** [August 27, 2009, 10:33am UTC](https://www.ruby-forum.com/t/how-to-include-modules-class-in-controller/174410/3 "2009-08-27T10:33:47Z")

</div>

If it is a class, why are you encapsulating it inside a module? You  
should be able to put the class rb file in your lib directory and use  
it in your controller. Make sure you name the file right. Again if  
you need to namespace it inside a module, just include the module in  
your controller using a “include ModuleName;” This will remove the  
need to do Module::Class every time. You can just use the ClassName  
afterwards, you don’t need to box it with a ModuleName::ClassName

On Aug 26, 6:13 pm, Vikas G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
