Heroku app crashes, logs say "No such file to load -- nokogiri (LoadError)" - ruby-on-rails-3

I had a working app, added Nokogiri, to parse some xml, runs fine locally.
My Gemfile includes: gem 'nokogiri'
I ran bundle install and verified my Gemfile.lock includes DEPENDENCIES ... nokogiri
In my controller class I added (didnt thinkI had to but got an error locally if I didnt):
class MydealController < ApplicationController
require 'rubygems'
require 'open-uri'
require 'nokogiri'
when I use my browser to get the url in MydealController that uses nokogiri doc = Nokogiri::XML(getresult) Heroku crashes.
heroku logs shows this error No such file to load -- nokogiri (LoadError)
Looking at what happens when I git push heroku I do not see nokogiri on the list of many many gems that get installed. Heroku says the push was fine, but nokogiri is not listed and I get the aforementioned error...

It seems that when using Windows Gemfile.lock will contain version of nokogiri gem specific for windows, solution is to remove Gemfile.lock and push to heroku.
More info on this subject here

Your mission should you choose to accept it.
Ensure:
nokogiri is in Gemfile.lock
Gemfile.lock is committed to git
you push the commit that has nokogiri in Gemfile.lock to Heroku
Good luck! This message will self destruct in 10 seconds...

Just had the same problem -- you have to run bundle install to get it added to the Gemfile.lock which heroku looks at to find uninstalled dependencies.

This might help to understand the reason:
http://devcenter.heroku.com/articles/ps
Indeed removing Gemfile.lock might help. All other compiled gem will cause isseu. Best way is to ask Heroku's support.
Only found this article:
http://ganeshprasadsr.blogspot.com/2010/10/installing-nokogiri-for-rails-3-app-on.html

Try to remove require 'nokogiri' from controller.
It works for me.

Related

Rails 3.2.11 performance testing issue: Don't know how to build task 'test:benchmark'

I'm following this railscast on performance testing, but I'm immediately running into an issue.
My app is rails 3.2.11, so according to the railscast it should include performance testing, but I don't have a folder called 'test' at all. When I run 'rails generate performance_test homepage' nothing happens or is generated. So I created one manually (to exactly match the railscast source code), but when I run rake test:benchmark I get the error
Don't know how to build task 'test:benchmark'
If I add the 'rails-perftest' gem to my gemfile and run bundle, then again try to generate a performance_test nothing happens, and when I then run rake test:benchmark, it throws a different error of
uninitialized constant Rails::SubTestTask
I've been sure to include the following dependencies in my gem file:
gem 'ruby-prof', group: :test
gem 'test-unit', group: :test
Could anyone help advise me what I'm doing wrong? Thanks!
I am not 100% certain on this, but I am guessing that you might not have your application.rb file configured accordingly. Also check your Gemfile.lock file and run the command bundle install because it could also be something funky going on with your Gems and dependencies.

rails 3 - LoadError (cannot load such file -- zip/zip)

I'm using rubyzip to zip a csv file so uses can download it. This works perfectly in development mode. But when I tried zipping the file on the production server (rackspace) I received the error: LoadError (cannot load such file -- zip/zip). Is it a path issue? Anyone know a fix?
The error is being called in my code on this line: require 'zip/zip'
I've tried the solution from here, but it didn't help.
I fixed this problem by specifying gem version 0.9.9 in Gemfile:
gem 'rubyzip', "~> 0.9.9"
Using rubyzip (1.0.0) caused an error.
When upgrading rubyzip to 1.0.0 change require 'zip/zip' to require 'zip'.
I had this problem after adding roo to a Rails project.
Roo needed the new interface, something else (some other gem) was using the old interface - so most of these answers didn't work (couldn't lower the version of rubyzip, rubyzip2 is deprecated, didn't have require zip/zip in my project).
What worked for me was cassio-s-cabral's answer referring to the rubyzip github page.
gem 'rubyzip', '>= 1.0.0' # will load new rubyzip version
gem 'zip-zip' # will load compatibility for old rubyzip API.
I had the same problem: error thrown on "require 'zip/zip'" code, and the solution from this post also did not help.
After a long research I found that the problem was that my "require 'zip/zip'" statement was done in a separate
lib/exporters/package_exporter.rb
file, and for some reason "require" statements are not handled in "lib" folder in production by default.
When I moved "require 'zip/zip'" to the beginning of my
app/controllers/packages_controller.rb
the problem was solved!
I had a similar issue with active_support, just added the 'zip' gem to my Gemfile and it worked fine
I'm use rubyzip2 gem to fix this problem
gem 'rubyzip2'
what work for me was to install 2 gems:
gem install rubyzip
gem install zip
and in the script put
require 'rubygems'
require 'zip/zip'
In their github page explains what to do.
Rubyzip interface changed!!! No need to do require "zip/zip" and Zip
prefix in class names removed.
If you have issues with any third-party gems what required old
version of rubyzip you can use next workaround:
gem 'rubyzip', '>= 1.0.0' # will load new rubyzip version
gem 'zip-zip' # will load compatibility for old rubyzip API.

Delayed_job(2.1.4) + Rails(3.0.10) undefined method `delay'

I upgrading a rails application to rails(3.0.10) and update the gem delayed_job. I updated my migration for the table delayed_job but unfortunatly the method ".delay" doesn't work.
NoMethodError: undefined method `delay' for #<User:0x10394d140>
I didn't find a solution for that. I did : "bundle install", I restarted the server, tried to instal as plugin...
Do you have any ideas?
Thanks.
UPDATE :
I fixed the problem but created a file config/initializer/delayed_job.rb with
require 'delayed_job'
Delayed::Worker.backend = :active_record
Sometimes gems just refuse to install properly. I think what you should do is (assuming you have git installed, otherwise go here https://github.com/tobi/delayed_job and download delayed_job as a zip file)
git clone https://github.com/tobi/delayed_job.git
take what he has in his lib folder and put it in yours. wherever you need to use his methods then do
require 'delayed_job'
in the top of those files
I checked this tutorial, it shows a way to setup in rails 3
http://www.dixis.com/?p=335
it suggests using this in your gemfile
gem "delayed_job", :git => 'git://github.com/collectiveidea/delayed_job.git'
(if it doesn't work with this either, then try the same thing that i did, but replace
git clone https://github.com/tobi/delayed_job.git
with
git clone https://github.com/collectiveidea/delayed_job.git
tell me if anything works

Global access to Rake DSL methods is deprecated

I am working through the Ruby on Rails 3 tutorial book and typed the following on the command line:
rake db:migrate
which produced the following warning.
WARNING: Global access to Rake DSL methods is deprecated. Please Include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method DemoApp::Application#task called at /Users/imac/.rvm/gems/ruby-1.9.2-p180#rails3tutorial/gems/railties-3.0.7/lib/rails/application.rb:215:in `initialize_tasks'
I am not sure what to do about it or how to work with it. I don't know any other command for Rake.
How can I fix this problem?
Adding include Rake::DSL to the Rakefile before the applications load_tasks were called also worked for me.
So in the above user's case before the DemoApp::Application.load_tasks in the Rakefile.
I found this in Stack Overflow question Ruby on Rails and Rake problems: uninitialized constant Rake::DSL. It refers to a #DHH tweet.
Put the following in your Gemfile
gem "rake", "0.8.7"
You may see something like
rake aborted!
You have already activated Rake 0.9.1 ...
I still had a copy of Rake 0.9.1 in my directory so I deleted it.
You can "delete" Rake 0.9.1 by running the following command:
gem uninstall rake -v=0.9.1
If you have multiple versions of the gem installed, you'll be prompted to pick a version.
After 0.9.1 was cleaned out, I ran
bundle update rake
and was finally able to create my database files. I was using rake db:create, but it should work for rake db:migrate as well.
I hope it helps.
I was having the same problem on Windows with the installer. Ruby 1.9.2 and Rails 3.0.9.
Here is what I did:
bundle update rake
bundle show rake
After doing that I was running rake 0.9.2.
Then I updated the Rakefile in application root folder as follows:
require File.expand_path('../config/application', __FILE__)
require 'rake'
# If you named your application something other than SampleApp, change that below
module ::SampleApp
class Application
include Rake::DSL
end
end
module ::RakeFileUtils
extend Rake::FileUtilsExt
end
SampleApp::Application.load_tasks
As noted in the comment, make sure the name of your app is correct in the two appropriate lines above.
If you are seeing this on later versions of Rails (like 3.+) you may also want to verify that your environment is clean by using RVM http://beginrescueend.com/ and creating a specific ruby & gemset for your projects.
Use an .rvmrc file on a per-project basis, this will guarantee you aren't getting older system gems into your projects. Which has bitten me before.
This prevents having to monkey around with generated Rakefiles & such.
bundle exec rake db:migrate will solve your ruby version issues

Rails 3 Initializers: No such file to load

I am trying to use the Sunlight API gem with a Rails project. I have installed the gem and can successfully use it from irb.
However, when I put the require statement (require 'sunlight') in sunlight.rb in config/initializers, I get the following error:
/opt/local/lib/ruby/gems/1.8/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:209:in `require': no such file to load -- sunlight (LoadError)
I checked the permissions on the gems directory, and it is world readable/executable.
Here is the code from sunlight.rb:
require 'rubygems'
require 'sunlight'
Sunlight::Base.api_key = 'bb7b775755054c54aa9715d202f6785c'
Can anyone tell me how to fix this? TIA!
Is sunlight listed in your Gemfile? Rails3 uses Bundler to manage Gem installations.