Ruby on Rails: Getting NameError whenever delayed_job gem is used - ruby-on-rails

Totally stumped on this one and hoping some RoR expert can help.
Hitting this strange error where if I install the delayed_job gem, my site (development env) just stops working. All controllers and methods will show a NameError exception:
NameError in ProductsController#show
cannot remove Object::ClassMethods
I know it's the delayed_job gem because if I uninstall it or comment it out, restart the server, the errors go away.
My gemfile looks like the following:
source 'http://rubygems.org'
gem 'rails', '3.0.10'
# Bundle edge Rails instead:
gem 'delayed_job', "2.1.4"
gem 'sqlite3'
gem 'faker', '0.3.1'
gem 'webrat', '0.7.1'
gem 'will_paginate', '3.0.pre2'
gem "amazon_product", "3.0.0.pre.2" #http://code.papercavalier.com/amazon_product/
gem "curb"
gem "authlogic"
gem "omniauth", ">=0.2.6"
gem "faraday"#, ">=0.7.4"
gem "fb_graph"
gem "twitter"#, "~> 1.7.1"
I am using Ruby 1.8.7 and Rails 3.0.10.
If you have any idea what might be the problem, please help :)

I figured out what the culprit was. In my controllers, I was including "#include ActionView::Helpers::TextHelper" at the top so I can use the truncate function. Including that apparently cause some naming conflicts withint delayed_job. Removing the include solved my problem.

Related

Phusion error: undefined method `has?' for Sass::Util:Module

I get the following error issued by Phusion when loading a web page:
There was an error while trying to load the gem 'compass-rails'.
Gem Load Error is: undefined method `has?' for Sass::Util:Module
Did you mean? hash
Hash
Backtrace for gem load error is:
/Volumes/Data/htdocs/zetcho/vendor/bundle/gems/compass-0.12.2/lib/compass/sass_extensions/functions/urls.rb:5:in `has?'
The code at the indicated location is:
module Compass::SassExtensions::Functions::Urls
def self.has?(base, instance_method)
Sass::Util.has?(:instance_method, base, instance_method)
end
My gem file contains:
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.2'
# Use mysql as the database for Active Record
gem 'mysql2', '~> 0.3.18'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Compass for stylesheets
gem 'compass-rails'
# Use the Compass extension susy
gem "sprockets"
gem 'susy'
I've just created the Ruby on Rails site using Rails 5.1.2 and ruby 2.3.1. I have a much older site that works fine with the gem. Did I miss a step in the overall install or is this a bug with compass-rails?
I got the same error when I tried to add a controller:
rails generate controller home index
After more digging around, I found a similar problem. I fixed this one by changing the gem file to:
gem 'compass-rails', github: 'Compass/compass-rails'
Then:
rm gemfile.lock
bundle
It seems that the issue can be found in compass-rails 2.0.0. The version 3.0.2 seems to fix this issues. So a possible solution is :
# Gemfile
gem 'compass-rails', '~> 3.0.2'
Then bundle update compass-rails
This avoids targeting the compass-rails git master branch in favor of an actual release.
I came here having the same issue with a grunt compiling issue trying to use Compass/Sass, if this might help someone, my issue was caused because I had an updated version of Sass (sass-3.7.4) that was higher that the max-version compatible with compass, I uninstalled sass:
gem uninstall sass
Which in turn uninstalled compass, and reinstalled compass letting it choose the right version, and problem solved.
gem install compass

`method_missing': undefined method `action_mailer' for #<Rails::Application::Configuration:0x00>

I am building a rails app and was using rails 4.0.1.
I had an error and noticed that it was mentioned as a bug on rails 3 months ago so I decided to: bundle update and got rails 4.0.3
after doing so neither the tests nor the server would start and they throw an error:
gems/railties-4.0.3/lib/rails/railtie/configuration.rb:95:in `method_missing': undefined method `action_mailer' for # (NoMethodError)
For the moment I commented out the action_mailer lines in the config/environments/* but it would be good to find a real solution.
Searching on Google didn't yield anything regarding this specific error.
Please let me know if I can provide any more detail.
Thank you very much.
UPDATE: here is my Gemfile
source 'https://rubygems.org'
ruby '2.0.0'
gem 'bootstrap-sass'
gem 'bootstrap_form'
gem 'coffee-rails'
gem 'rails'
gem 'haml-rails'
gem 'sass-rails'
gem 'uglifier'
gem 'jquery-rails'
gem 'bcrypt-ruby', '~> 3.1.2'
group :development do
gem 'sqlite3'
gem 'thin'
# gem "better_errors"
gem "binding_of_caller"
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development, :test do
gem 'rspec-rails'
gem 'pry'
gem 'pry-nav'
end
group :test do
gem "faker"
gem "capybara"
gem "database_cleaner"
gem "launchy"
gem 'shoulda-matchers'
gem "selenium-webdriver"
gem "fivemat"
gem 'fabrication'
end
Solution found, in case anyone lands here:
The main issue was that in my Gemfile as you can see no specific gem version was set (apart from bcrypt)
Somehow this makes bundle installs outdated versions under circumstances that are not yet clear to me.
Steps to fix:
completely remove the gemset (if you are using one) or uninstall all
gems
remove the Gemfile.lock
specifiy what version of rails you need e.g. 'rails', '~> 4.0.3'
bundle install
you are set :)
in my case I had installed the gems and since the devkit was not installed properly the gems did not compile.
After setting up the devkit I had to uninstall all of the rails gems (actionmailer, activerecord, actioncable......) and then install rails again.
Then it worked.

Ruby on Rails: BlueCloth gem cannot work in production when deployed to heroku

I'm trying to use the BlueCloth gem in order to parse some markdown for my rails app. I added it to my gem file:
gem 'BlueCloth'
In my .html.erb views I user the code
<%= BlueCloth.new(post.content).to_html.html_safe %>
To render the markdown as html. This works completely fine in my local dev environment, but when I push to heroku, even after running bundle install and restarting the app, accessing the app generates internal server errors.
I get the following error in the logs:
ActionView::Template::Error (uninitialized constant ActionView::CompiledTemplates::BlueCloth):
I include BlueCloth in the gem file:
source 'https://rubygems.org'
gem 'rails', '3.2.8'
gem 'pg'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'devise'
gem 'BlueCloth'
I have also run the command bundle install via the heroku command line.
Thanks for the help!
It looks like your manually requiring files. It might be easier for you if you use bundler to require everything for you and then you dont have to add require to any other .rb file. Its very simple to do this. Depending on your Rails version, here are two links that should help you out:
Rails 2.3
Rails 3
The issue was that I was using the old version of the BlueCloth gem.
The old gem is called BlueCloth and the new one is called bluecloth
Changing the line in my gem file:
gem 'BlueCloth'
To:
gem `bluecloth`
Fixed it.
Thanks.

Rails has disappeared

I developed a web in rails and it was working perfectly for months. Now I went to my web folder and started "rails server" but got the reply:
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
I really don't understand how rails could disappeared from my system, I am sure I haven't removed it. I was using rails 3.1 on a Mac. Any clues or suggestions?
Gemfile:
source 'rubygems.org';
gem 'rails', '3.1.0.rc5'
# gem 'rails', :git => 'git://github.com/rails/rails.git'
#group :test, :production do
# gem 'mysql', '5.1.58'
#end
#group :development do gem 'sqlite3'
#end
#gem install activerecord-mysql-adapter
gem 'json'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', "~> 3.1.0.rc"
gem 'coffee-rails', "~> 3.1.0.rc"
gem 'uglifier'
end
gem 'jquery-rails'
I have faced a similar problem.
I believe rails 3.1.0 is buggy, i myself tried my hands on it and reverted back to the stable version of rails i.e. anything but 3.1.0. It would have been better if you have installed RVM. With RVM you can have one or more rails version, in fact an entire gemset.
I myself have a global gemset and another gemset named rails1.
rvm gemset create gemset_name
Once you install the like of ruby and rails version you can set it default
rvm gemset default#gemset_name
I did this back then and it works fine on my end. More on RVM
Hope it helps.

Launching RoR server for an existing app gives error

I just made my first setup of RoR, and creating a new application works fine. But when I want to run the rails server I get the following error:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/delayed_job-2.1.3/lib/delayed/yaml_ext.rb:30:in 'remove_method': method 'to_yaml' not defined in Class (NameError)
I ran the "bundle install" in the app directory and installed all the necessary files (with some problems however, but I excluded the gems with problems in the gemfile) and the last bundle install said that I have successfully installed all the needed packs.
I'm lost and I can't find a similar error on the internet. Can you help me?
EDIT: I forgot to mention that I'm not having a problem with a new application. It's running an existing one (that I didn't build, but works fine for others) that the error is related to. Here's the gemfile for that app:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'mysql'
gem "haml", ">= 3.0.0"
gem "haml-rails"
gem 'simple_form'
gem 'delayed_job'
#gem 'auto_crawlers'
gem 'will_paginate', '~> 3.0.beta'
group :test do
gem 'factory_girl_rails'
gem 'mocha'
end
group :development do
#gem "nifty-generators", "0.4.3", :git => "git://github.com/JonasNielsen/nifty-generators.git"
gem 'fastercsv'
end
gem "mocha", :group => :test
Do you think the error is because I left out the two gems with "#" ? Those were causing problems at first, and I don't think I need them to test some minor changes in the app (some views that I have to modify)
The issue is being described, and supposedly fixed here: https://github.com/collectiveidea/delayed_job/issuesearch?state=open&q=yaml#issue/194
Try this from the command line: irb -rubygems -r delayed_job and then from your bundled directory bundle-exec irb -rubygems -r delayed_job which will show if there is a difference between your system gems and your bundled setup - you might see an error in one or both attempts to run IRB.
If there is an error using bundle-exec but not with your system gems then it's a bundler issue. If not, are you sure the app is designed to function under Ruby 1.9? It looks like to_yaml isn't available at the point DJ is required, which implies it probably needs a require "yaml" somewhere.

Resources