tags:

views:

539

answers:

2

I'm trying to get the sanitize gem up and running. I've installed sanitize and nokogiri 1.3.3 as required, but when I try and use it in my application_helper.rb:

require 'rubygems'
require 'sanitize'

I get the error:

MissingSourceFile 
no such file to load -- sanitize
RAILS_ROOT: C:/Ruby/GWS

(stack trace)

This error occurred while loading the following files:
   sanitize

I also get the error if I require nokogiri, but I don't if I require another gem such as rmagick.

I've tried uninstalling and reinstalling both nokogiri and santitize, but with no luck.

Update: If I run the require command from irb I get an error about racc not being found. If I try to install racc I get the error message at http://stackoverflow.com/questions/1136548/error-while-installing-ruby-gem

A: 

Have you tried installing racc with the answer given in that question? There are comments also on further errors.

If that doesn't work, you can always try vendoring sanitize, see if that works alright. In your command line:

cd C:/myapp/vendor
gem unpack sanitize

Then in your application:

require 'vendor/sanitize/lib/sanitize'

Adjust the above for different directory naming/structure of course.

ehsanul
Tried the other answer and got the exact same problems. Tried the vendor idea but it didn't make any difference.
Mike Sutton
A: 

Here's how I fixed it.

Add the following to config/environment.rb

Rails::Initializer.run do |config|
  config.gem 'nokogiri', :version => '~> 1.3.3', :source => 'http://gems.github.com'
end

gem 'nokogiri', '~> 1.3.3'

require 'nokogiri'

Rails::Initializer.run do |config|
  config.gem 'sanitize', :version => '~> 1.1.0', :source => 'http://gems.github.com'
end

gem 'sanitize', '~> 1.1.0'

require 'sanitize'

then run

rake gems:install

(I also had to uninstall and reinstall the gems but that may have been due to problems with one of my gem sources which I had added after the original issue arose).

Mike Sutton