Posts about Rails

no such file to load — /vendor/rails/railties/lib/initializer

July 30th, 2008

When deploying with capistrano, using git, and rails as a submodule in vendor/rails, you might run into the following error:


** [out :: domain] (in /var/www/apps/domain/releases/20080730043012)
** [out :: domain] rake aborted!
** [out :: domain] no such file to load –/var/www/apps/domain/releases/20080730043012/config/../vendor/rails/railties/lib/initializer
** [out :: domain] /var/www/apps/domain/releases/20080730043012/Rakefile:4
** [out :: domain] (See full trace by running task with –trace)

When you check to see why it can’t find the file you’ll see /vendor/rails is empty. Once you understand why it’s empty (because it’s a git submodule), you’ll realize that capistrano isn’t doing the necessary commands to initialize that submodule. These commands are:


git submodule init
git submodule update

Luckily, capistrano has added support for this by using the following in your deploy.rb.


set :git_enable_submodules, true

That will cause capistrano to execute the necessary commands for submodules:


if configuration[:git_enable_submodules]
  execute << "#{git} submodule #{verbose} init"
  execute << "#{git} submodule #{verbose} update"
end

super: no superclass method `require’ (NoMethodError)

July 30th, 2008

I had an issue a few hours ago where I was getting the following message when running script/server after trying to do a deployment.

super: no superclass method `require' (NoMethodError)

The problem seemed to be a mix of haml and rails 2.1. It worked on my development machine though, so there is probably something more to it than that.

After spending some time trying to find the issue I eventually found that this was the reason of failure :

(/usr/lib/ruby/gems/1.8/gems/haml-2.0.1/lib/haml.rb:1033):


%w[haml/template sass sass/plugin].each(&method(:require))

I wasn’t totally sure what that is expected to do. I figured at first maybe it was supposed to be a Symbol#to_proc conversion, but method isn’t a symbol, so I’m still not totally sure what that is supposed to do. Anyway, what’s important is that I replaced it with:


%w[haml/template sass sass/plugin].each { |x| require x }

After that everything worked just fine.

The full trace I received with the error is listed below:

=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails 2.1.0 application starting on http://0.0.0.0:1200
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:1200
** Starting Rails with production environment...
Exiting
/var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/dependencies.rb:144:in `require': super: no superclass method `require' (NoMethodError)
from /var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in `new_constants_in'
from /var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/dependencies.rb:144:in `require'
from /var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb:36:in `to_proc'
from /usr/lib/ruby/gems/1.8/gems/haml-2.0.1/lib/haml.rb:1033:in `each'
from /usr/lib/ruby/gems/1.8/gems/haml-2.0.1/lib/haml.rb:1033:in `init_rails'
from /var/www/apps/domain/releases/20080730050116/vendor/plugins/haml/init.rb:7:in `evaluate_init_rb'
from ./script/../config/../vendor/rails/railties/lib/rails/plugin.rb:103:in `evaluate_init_rb'
from /var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
from ./script/../config/../vendor/rails/railties/lib/rails/plugin.rb:99:in `evaluate_init_rb'
from ./script/../config/../vendor/rails/railties/lib/rails/plugin.rb:44:in `load'
from ./script/../config/../vendor/rails/railties/lib/rails/plugin/loader.rb:33:in `load_plugins'
from ./script/../config/../vendor/rails/railties/lib/rails/plugin/loader.rb:32:in `each'
from ./script/../config/../vendor/rails/railties/lib/rails/plugin/loader.rb:32:in `load_plugins'
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:311:in `load_plugins'
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:150:in `process'
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:105:in `send'
from ./script/../config/../vendor/rails/railties/lib/initializer.rb:105:in `run'
from /var/www/apps/domain/releases/20080730050116/config/environment.rb:13
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from /var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/dependencies.rb:144:in `require'
from /var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in `new_constants_in'
from /var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/dependencies.rb:144:in `require'
from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:147:in `rails'
from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:113:in `cloaker_'
from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:149:in `call'
from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:149:in `listener'
from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:99:in `cloaker_'
from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:50:in `call'
from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:50:in `initialize'
from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:84:in `new'
from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:84:in `run'
from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/command.rb:212:in `run'
from /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281
from /var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/dependencies.rb:137:in `load_without_new_constant_marking'
from /var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/dependencies.rb:137:in `load'
from /var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in `new_constants_in'
from /var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/dependencies.rb:137:in `load'
from /var/www/apps/domain/releases/20080730050116/vendor/rails/railties/lib/commands/servers/mongrel.rb:64
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from /var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/dependencies.rb:144:in `require'
from /var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/dependencies.rb:503:in `new_constants_in'
from /var/www/apps/domain/releases/20080730050116/vendor/rails/activesupport/lib/active_support/dependencies.rb:144:in `require'
from /var/www/apps/domain/releases/20080730050116/vendor/rails/railties/lib/commands/server.rb:49
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from script/server:3

Undefined method ‘capture_erb_with_buffer’

June 21st, 2008

I just ran into this issue when starting a new rails project, and attempting to use the script/generate resource generator. You might get an error like this:

/Library/Ruby/Gems/1.8/gems/haml-2.0.0/lib/haml/helpers/action_view_mods.rb:46:in `alias_method': undefined method `capture_erb_with_buffer' for module `ActionView::Helpers::CaptureHelper' (NameError)

If you do, the solution is to open up that file (action_view_mods.rb) in a text editor and find the lines:


        alias_method :capture_erb_with_buffer_without_haml, :capture_erb_with_buffer
        alias_method :capture_erb_with_buffer, :capture_erb_with_buffer_with_haml

And change them to:


        alias_method :capture_erb_with_buffer, :capture_erb_with_buffer_with_haml
        alias_method :capture_erb_with_buffer_without_haml, :capture_erb_with_buffer

For some reason it was referencing an aliased method before it aliased it.