How to include module's class in controller?

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.

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

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. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs