# Where to put require 'gem' statements?

**URL:** <https://www.ruby-forum.com/t/where-to-put-require-gem-statements/183750>\
**Category:** Rails\
**Created:** [February 19, 2010, 12:53pm UTC](https://www.ruby-forum.com/t/where-to-put-require-gem-statements/183750 "2010-02-19T12:53:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pytlik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/779978/32.png) [@pytlik](https://www.ruby-forum.com/u/pytlik)\
**Post date:** [February 19, 2010, 12:53pm UTC](https://www.ruby-forum.com/t/where-to-put-require-gem-statements/183750/1 "2010-02-19T12:53:50Z")

</div>

Hello,

I’ve seen all sorts of places where people put their ‘require’  
statements,  
and I’m not sure what the best solution is. I’m currently using it  
directly  
in a model/csv\_processor.rb:

require ‘fastercsv’

class CsvProcessor  
def self.create\_csv\_table(file)  
…  
FCSV.parse(…  
…  
end

I’m calling this from controllers/loader\_controller.db:

my\_csv\_table = CsvProcessor.create\_csv\_table(params[:file\_ref])

Works perfectly. But generally, where is the place to put all those  
require statements? Is it in config/environment.rb? Would it be correct  
to add them just at the end of this file?

I already tried this with another “processor”, which needs the  
ruby-plsql  
gem. So I added at the end of environment.rb the statements:

require ‘ruby-plsql’  
plsql.activerecord\_class = ActiveRecord::Base  
plsql.connection.autocommit = false

But this didn’t work. I couldn’t start webrick anymore. Having instead  
the same statements at the beginning of model/plsql\_processor.rb  
works without problems.

Any help would be appreciated,

Martin

---

<div class="post-metadata">

**Author:** ![pytlik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/779978/32.png) [@pytlik](https://www.ruby-forum.com/u/pytlik)\
**Post date:** [February 19, 2010, 2:07pm UTC](https://www.ruby-forum.com/t/where-to-put-require-gem-statements/183750/2 "2010-02-19T14:07:23Z")

</div>

On Feb 19, 11:53 am, Martin B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Works perfectly. But generally, where is the place to put all those  
> require statements? Is it in config/environment.rb? Would it be correct  
> to add them just at the end of this file?

Well if it’s a gem then using config.gem inside config/environment.rb  
is usually the way to go. You don’t want to just stick things at the  
bottom of environment.rb - in production mode your app’s code gets  
loaded before the bottom of environment.rb gets executed. If you put  
stuff in an initializer (ie in a file in config/initializers) then it  
will get run early enough.

Fred
