I intend to write articles covering actual programming soon, as opposed to the hodge-podge, link-filled, advocacy-style articles I have written up to now. In spite of that, I hope that the couple short blurbs about Rails or Merb errors do help a person or two. These little things can be frustrating as hell.
Where Did This Error Come From?
If you have gotten this error, you are probably using Haml and Sass in your Merb application, right? You installed Haml, wrote a few views with it, and then decided to move on and generate the next controller or model, right? Right. This is probably what it looks like:
>script/generate controller sessions
Connecting to database...
/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active\_support/dependencies.rb
:266:in \`load\_missing\_constant': uninitialized constant MERB\_ROOT (NameError)
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active\_support/dependencies.rb
:453:in \`const\_missing'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active\_support/dependencies.rb
:465:in \`const\_missing\_before\_generators'
from /usr/lib/ruby/gems/1.8/gems/rubigen-1.1.1/lib/rubigen/lookup.rb:13:in \`const\_missing'
from /usr/lib/ruby/gems/1.8/gems/haml-1.8.0/lib/sass/plugin/merb.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 /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active\_support/dependencies.rb
:496:in \`require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active\_support/dependencies.rb
:342:in \`new\_constants\_in'
... 23 levels...
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active\_support/dependencies.rb
:496:in \`require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active\_support/dependencies.rb
:342:in \`new\_constants\_in'
from /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/
active\_support/dependencies.rb
:496:in \`require'
from script/generate:12
Crap. What do I do?
Ardekantur knows what to do. His blurb on the subject is what helped me. I ended up opening the Sass’ Merb plugin file in Vim, and replacing it all with the trunk version.
Open the file.
sudo vim /usr/lib/ruby/gems/1.8/gems/haml-1.8.0/lib/sass/plugin/merb.rb
Save that. Then try your script/generate line again. It should work now.
Wait, Don’t Go Yet!
Really, Ardekantur did all the work. I sort of feel like I plagiarized this whole article. You should go ahead and check out his blog. In particular, he has written an article Writing A Web Application In Merb, Part I, in which he exudes a test-first attitude, and uses RSpec, both of which are a Good Thing. I think I’m going to subscribe in anticipation of the next part (I assume II, or maybe J). You should at least take a look!