Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require ruby gems in rails controller

require 'rubygems'
require 'mechanize'

agent = Mechanize.new
page = agent.get("http://google.com/")

This simple script works ok.

But if I'am trying to add require 'rubygems' and require 'mechanize' to the Rails controller, server gives:

LoadError in NewsController#find
no such file to load -- mechanize

I use RVM on Ubuntu 10.04 server machnine. Ruby version: 1.9.2, Rails version: 3.0.3. Server: Passanger under Apache2.

P.S. If I run rails server and go to mysite.com:3000 all works without any error, so there is a problem with Passanger!

Please, help me!

like image 870
Kir Avatar asked Feb 08 '11 08:02

Kir


1 Answers

You shouldn't require gems in your controller. Thats why Bundler was added to Rails 3. Just add mechanize to your Gemfile like this

gem "mechanize"

and run

bundle install

on the command line. Any gem mentioned here will be required on application startup.

like image 64
flitzwald Avatar answered Oct 17 '22 07:10

flitzwald