# Accessing module from controller

**URL:** <https://www.ruby-forum.com/t/accessing-module-from-controller/187626>\
**Category:** Rails\
**Created:** [April 27, 2010, 12:27am UTC](https://www.ruby-forum.com/t/accessing-module-from-controller/187626 "2010-04-27T00:27:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveh0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@daveh0](https://www.ruby-forum.com/u/daveh0)\
**Post date:** [April 27, 2010, 12:27am UTC](https://www.ruby-forum.com/t/accessing-module-from-controller/187626/1 "2010-04-27T00:27:02Z")

</div>

I know this is probably something simple that I’m missing. I am trying  
to call a function that is in a module in /lib, but the controller  
doesnt seem to be finding it.

I have:

lib/siteopen.rb:

module Siteopen  
def is\_site\_open()  
return 1  
end  
end

and in a controller:

class StartupController \< ApplicationController  
require ‘Siteopen’

def index  
if is\_site\_open()  
@sitemsg=“The site is now open”  
else  
@sitemsg=“Site is closed.”  
end  
end  
end

This will give me the following error:

NoMethodError in StartupController#index  
undefined method `is\_site\_open’ for #StartupController:0x1045b2ea8

I’m sure it’s something dumb I’m doing.  
Thanks…

---

<div class="post-metadata">

**Author:** ![daveh0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@daveh0](https://www.ruby-forum.com/u/daveh0)\
**Post date:** [April 27, 2010, 12:31am UTC](https://www.ruby-forum.com/t/accessing-module-from-controller/187626/2 "2010-04-27T00:31:45Z")

</div>

On Apr 26, 11:27 pm, Dave P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I know this is probably something simple that I’m missing. I am trying  
> to call a function that is in a module in /lib, but the controller  
> doesnt seem to be finding it.

If you want to be able to use the methods from a module like that you  
need to include the module (or extend it if you just want to add the  
methods to one instance). require (which is unnecessary here) just  
asks ruby to load the file.

Fred

---

<div class="post-metadata">

**Author:** ![daveh0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/34f0e0/32.png) [@daveh0](https://www.ruby-forum.com/u/daveh0)\
**Post date:** [April 27, 2010, 12:44am UTC](https://www.ruby-forum.com/t/accessing-module-from-controller/187626/3 "2010-04-27T00:44:14Z")

</div>

Frederick C. wrote:

> If you want to be able to use the methods from a module like that you  
> need to include the module (or extend it if you just want to add the  
> methods to one instance). require (which is unnecessary here) just  
> asks ruby to load the file.
> 
> Fred

That was it!  
Thanks,Dave
