# Where do I 'require' a gem?

**URL:** <https://www.ruby-forum.com/t/where-do-i-require-a-gem/69920>\
**Category:** Rails\
**Created:** [September 25, 2006, 4:42pm UTC](https://www.ruby-forum.com/t/where-do-i-require-a-gem/69920 "2006-09-25T16:42:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brett\_KeltsSKelte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4da419/32.png) [@Brett\_KeltsSKelte](https://www.ruby-forum.com/u/Brett_KeltsSKelte)\
**Post date:** [September 25, 2006, 4:42pm UTC](https://www.ruby-forum.com/t/where-do-i-require-a-gem/69920/1 "2006-09-25T16:42:44Z")

</div>

I’m using the login\_system gem which works fine on my dev. environment  
(RadRails / webbrick). Also my hosting company (A2) installed the same  
GEM. But when I try to login on the production server, I get:

NoMethodError in AccountController#login

undefined method `redirect\_back\_or\_default’ for  
#AccountController:0x2a96ffa088

Does there need to be a require somewhere?

---

<div class="post-metadata">

**Author:** ![Brett\_KeltsSKelte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4da419/32.png) [@Brett\_KeltsSKelte](https://www.ruby-forum.com/u/Brett_KeltsSKelte)\
**Post date:** [September 25, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/where-do-i-require-a-gem/69920/2 "2006-09-25T16:51:59Z")

</div>

Brett Kelts - [KeltexIS.com](http://KeltexIS.com) wrote:

> I’m using the login\_system gem which works fine on my dev. environment  
> (RadRails / webbrick). Also my hosting company (A2) installed the same  
> GEM. But when I try to login on the production server, I get:
> 
> NoMethodError in AccountController#login
> 
> undefined method `redirect\_back\_or\_default’ for  
> #AccountController:0x2a96ffa088
> 
> Does there need to be a require somewhere?

RubyGems have their own ‘require\_gem’ that is like ‘require’ but for  
gems. You can put that in your environment.rb or  
environments/production.rb, depending on if you want it in all  
environments or just production.

require\_gem ‘login\_system’

I’ve never used the login\_system gem so I don’t know if there are other  
dependencies that might be screwing you up. It may be that A2 messed up  
the gem installation somehow.

–  
Josh S.  
[http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

---

<div class="post-metadata">

**Author:** ![Brett\_KeltsSKelte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4da419/32.png) [@Brett\_KeltsSKelte](https://www.ruby-forum.com/u/Brett_KeltsSKelte)\
**Post date:** [September 25, 2006, 5:37pm UTC](https://www.ruby-forum.com/t/where-do-i-require-a-gem/69920/3 "2006-09-25T17:37:02Z")

</div>

Thanks for your feedback.

I added require\_gem ‘login\_generator’ to the environment.rb, but no  
dice. How would I determine what other dependencies are required?

When the gem was installed in my environment it created the file  
login\_system.rb in my lib directory. This defines a module LoginSystem  
which includes the method redirect\_back\_or\_default.

Does this somehow need to be included? Still don’t understand why it  
complains in production mode but is fine in dev. mode.

---

<div class="post-metadata">

**Author:** ![Brett\_KeltsSKelte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4da419/32.png) [@Brett\_KeltsSKelte](https://www.ruby-forum.com/u/Brett_KeltsSKelte)\
**Post date:** [September 25, 2006, 7:55pm UTC](https://www.ruby-forum.com/t/where-do-i-require-a-gem/69920/4 "2006-09-25T19:55:28Z")

</div>

You have to “include” the LoginSystem in ApplicationController:

class ApplicationController \< ActionController::Base  
include LoginSystem  
…  
end

Vish

---

<div class="post-metadata">

**Author:** ![Brett\_KeltsSKelte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4da419/32.png) [@Brett\_KeltsSKelte](https://www.ruby-forum.com/u/Brett_KeltsSKelte)\
**Post date:** [September 28, 2006, 9:15pm UTC](https://www.ruby-forum.com/t/where-do-i-require-a-gem/69920/5 "2006-09-28T21:15:26Z")

</div>

I just wanted to give everybody an update. I was completely frustrated  
with this gem. The hosting company (A2) gave me their response:  
“Unfortunately, it is beyond the scope of our support to debug  
applications/code for customers”

Anyway, I cancelled my account with them and moved over to DreamHost.  
Followed their very through Wiki instructions and it now works  
perfectly.

---

<div class="post-metadata">

**Author:** ![Brett\_KeltsSKelte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4da419/32.png) [@Brett\_KeltsSKelte](https://www.ruby-forum.com/u/Brett_KeltsSKelte)\
**Post date:** [April 18, 2008, 1:02pm UTC](https://www.ruby-forum.com/t/where-do-i-require-a-gem/69920/6 "2008-04-18T13:02:40Z")

</div>

nice,

i suppose on top of this you could create a file in your  
/config/initializers/ directory to load all the gems your app needs;  
making things a little more neat.

haven’t tried myself but should be possible rather than sticking it into  
your environment.rb file all the time

---

<div class="post-metadata">

**Author:** ![Brett\_KeltsSKelte](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4da419/32.png) [@Brett\_KeltsSKelte](https://www.ruby-forum.com/u/Brett_KeltsSKelte)\
**Post date:** [September 26, 2006, 2:46am UTC](https://www.ruby-forum.com/t/where-do-i-require-a-gem/69920/7 "2006-09-26T02:46:18Z")

</div>

On Sep 25, 2006, at 7:51 AM, Josh S. wrote:

> > undefined method `redirect\_back\_or\_default’ for
> 
> I’ve never used the login\_system gem so I don’t know if there are  
> other  
> dependencies that might be screwing you up. It may be that A2  
> messed up  
> the gem installation somehow.
> 
> –  
> Josh S.  
> [http://blog.hasmanythrough.com](http://blog.hasmanythrough.com)

```
No, require_gem is deprecated and should not be used unless you need

```

to require a specific version of a gem. It will be removed in  
subsequent rubygems releases. Don’t use it because it is misleading  
and doesn’t really do what it seems like it should do. TO require an  
installed gem you only need to do this:

require ‘rubygems’  
require ‘gemname’

And rails already requires rubygems unless you have rails frozen in  
vendor.

-Ezra
