# RubyGem loading into a controller (High quality question)

**URL:** <https://www.ruby-forum.com/t/rubygem-loading-into-a-controller-high-quality-question/85690>\
**Category:** Rails\
**Created:** [March 23, 2006, 12:19am UTC](https://www.ruby-forum.com/t/rubygem-loading-into-a-controller-high-quality-question/85690 "2006-03-23T00:19:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 23, 2006, 12:19am UTC](https://www.ruby-forum.com/t/rubygem-loading-into-a-controller-high-quality-question/85690/1 "2006-03-23T00:19:56Z")

</div>

INSTALLATION:

Ruby 1.8.2  
Rails 1.0.0  
rubyful\_soup 1.0.4 (GEM)

FACTS:  
0) I have successfully installed the rubyful\_soup GEM using (I had  
previously installed it, which is why the output may look sparse):

C:\ruby\>gem install -r rubyful\_soup  
Attempting remote installation of ‘rubyful\_soup’  
Successfully installed rubyful\_soup-1.0.4  
Installing RDoc documentation for rubyful\_soup-1.0.4…

1. I have a controller. The first 4 lines are:

require ‘rubygems’  
require\_gem ‘rubyful\_soup’, ‘\>= 1.0.4’

class ESimplyController \< ApplicationController

1. In this controller I have a method. Here it is:

public  
def index  
parser = BeautifulSoup.new(String.new “test”) #Establish the parse  
tree  
end

When I execute this action, I get:

“uninitialized constant BeautifulSoup”

which basically tells me that the BeautifulSoup class within the  
rubyful\_soup.rb file can’t be seen.

1. Inside of the rubyful\_soup.rb file, the BeautifulSoup class is  
defined, like so:

class BeautifulSoup \< BeautifulStoneSoup  
…

QUESTION 1: Have I correctly included this RubyGem?

QUESTION 2: Does something else need to be done to successfully export  
the BeautifulSoup class name so that it’s accessible?

QUESTION 3: Does something else need to be done to successfully import  
the BeautifulSoup class name so that it’s accessible?

Thanks for any help that you can provide. I am at my wit’s end.

To top it all off, at random times and under circumstances that I am  
unable to recreate, this was totally working for me. I do not  
understand what is wrong.

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 23, 2006, 12:42am UTC](https://www.ruby-forum.com/t/rubygem-loading-into-a-controller-high-quality-question/85690/2 "2006-03-23T00:42:14Z")

</div>

There appears to be a time component to my problem. If I leave my  
WEBrick server up for a few minutes (maybe 5 maybe 10 I’m not sure), all  
of a sudden it can find the GEM and everything works.

Perhaps there is some kind of caching going on with autoloading of  
classes???

Wes G. wrote:

> INSTALLATION:
> 
> Ruby 1.8.2  
> Rails 1.0.0  
> rubyful\_soup 1.0.4 (GEM)

…

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [March 23, 2006, 6:47pm UTC](https://www.ruby-forum.com/t/rubygem-loading-into-a-controller-high-quality-question/85690/3 "2006-03-23T18:47:46Z")

</div>

SOLUTION:

Apparently

require\_gem

doesn’t actually require anything, it just enforces the versioning  
rules.

So I needed to do

require ‘rubygems’  
require ‘rubyful\_soup’  
require\_gem ‘rubyful\_soup’, ‘\>= 1.0.4’

WG

Wes G. wrote:

> There appears to be a time component to my problem. If I leave my  
> WEBrick server up for a few minutes (maybe 5 maybe 10 I’m not sure), all  
> of a sudden it can find the GEM and everything works.
> 
> Perhaps there is some kind of caching going on with autoloading of  
> classes???
> 
> Wes G. wrote:
> 
> > INSTALLATION:
> > 
> > Ruby 1.8.2  
> > Rails 1.0.0  
> > rubyful\_soup 1.0.4 (GEM)
> 
> …
