Where do I 'require' a gem?

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?

Brett Kelts - 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

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.

You have to “include” the LoginSystem in ApplicationController:

class ApplicationController < ActionController::Base
include LoginSystem

end

Vish

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.

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

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

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

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