undefined method `init_rails' for Haml:Module (NoMethodError)

64 views
Skip to first unread message

Jay

unread,
Jun 30, 2008, 6:47:05 PM6/30/08
to Haml
I'm hitting an error the solution to which I suspect will be painfully
obvious.

I'm on Rails 2.1 and have just installed haml via git. When I try to
start the rails app, I get the following error:

undefined method `init_rails' for Haml:Module (NoMethodError)

Has anyone bumped into this?

Thanks!

Nathan Weizenbaum

unread,
Jun 30, 2008, 9:18:02 PM6/30/08
to ha...@googlegroups.com
How exactly did you install Haml?

Jay

unread,
Jun 30, 2008, 9:25:17 PM6/30/08
to Haml
Hi there. Yeah, I seem to have just plain missed a lot of the files.
Here's what I did:

git clone git://github.com/nex3/haml.git
cd haml
sudo rake install
haml --rails /path/to/my/app

And I got no error messages-- it acted like it installed fine. It
copied a file into the vendor/plugins folder, but did not copy any
files in to lib. I'm moving them over manually now and have just
gotten past the init_rails issue, but there seems to be quite a bit of
stuff out of place, so I'm going through and trying to find what's
missing. (currently VERSION is out of place).

Nathan Weizenbaum

unread,
Jun 30, 2008, 9:35:10 PM6/30/08
to ha...@googlegroups.com
haml --rails is only supposed to add one file - it loads the rest from
the gem. Try getting rid of vendor/plugins/haml/lib entirely, and try
again. If that doesn't work, what output does "haml --version" give you?

Jay

unread,
Jun 30, 2008, 9:59:08 PM6/30/08
to Haml
haml --version
Haml 2.1.0.ff425bd

Regarding vendor/plugins/haml/lib, that's the thing-- there is no
'lib' in vendor/plugins/haml. When I run the haml --rails command, I
end up with only a single file: vendor/plugins/haml/init.rb.

Trying your suggestion regarding removing the directories entirely.
Thanks very much, by the way.

Jay

unread,
Jun 30, 2008, 10:02:21 PM6/30/08
to Haml
haml --version
Haml 2.1.0.ff425bd

Regarding vendor/plugins/haml/lib, that's the thing-- there is no
'lib' in vendor/plugins/haml. When I run the haml --rails command, I
end up with only a single file: vendor/plugins/haml/init.rb.

Trying your suggestion regarding removing the directories entirely.
Thanks very much, by the way.

Jay

unread,
Jun 30, 2008, 10:39:06 PM6/30/08
to Haml
No luck there. I remove everything haml I can find and then as
before:

git clone git://github.com/nex3/haml.git
cd haml
sudo rake install
haml --rails /path/to/my/app

which gives me only

vendor/plugins/haml/init.rb

but no other directories or files.

Strangely, vendor/plugins/haml is always owned by 'root' instead of by
me, so maybe a permission issue with the install script? I'll report
back here if I can find anything. Thanks again.

Nathan Weizenbaum

unread,
Jun 30, 2008, 11:03:49 PM6/30/08
to ha...@googlegroups.com
haml --rails is only supposed to install vendor/plugins/haml/init.rb.
The rest is loaded from the gem.

The standard way to install the gem from source is to run "rake install"
without sudo - the rake task should sudo when it needs to - so that may
be the cause of the permissions thing. Does it work if you chmod the
plugin dir so that you have write access?

Jay

unread,
Jul 1, 2008, 6:21:41 AM7/1/08
to Haml
Ok, so I removed haml on both dev & production box:

sudo gem uninstall haml
(all versions)

And then reinstalled on dev & production:

git clone git://github.com/nex3/haml.git
cd haml
rake install [no sudo this time]

Everything is fine, no errors. On the dev box:

haml --rails /path/to/my/app

and then checked into git, commit & deploy. Now in production I have

rails --version
Rails 2.1.0

gem --version
1.2.0

haml --version
Haml 2.1.0.ff425bd

and in the plugins directory

init.rb

But still

undefined method `init_rails' for Haml:Module (NoMethodError)

Which means the gem isn't loading properly. As per init.rb, if I move
the haml files into vendor/plugins/haml they will be picked up, but
with all sorts of other wonky errors.

Regarding your question about chown-ing the directory, no, I tried
that before to no avail. But this time I installed it without sudo
and now no problems with ownership that I can see.

So that's the assumption I'm working with now: that in init.rb,
"require 'haml'" isn't picking up the gem somehow.

Hmm.

Nathan Weizenbaum

unread,
Jul 1, 2008, 9:30:52 AM7/1/08
to ha...@googlegroups.com
What happens if you try requiring Haml from IRB? Does #init_rails exist?

Jay

unread,
Jul 1, 2008, 9:53:49 AM7/1/08
to Haml
I had tried that, but I read somewhere that in irb require
'whatevergem' often throws false because it's already loaded. Which
may be wrong or may not apply to this situation.

irb(main):004:0> require 'haml'
LoadError: no such file to load -- haml
from (irb):4:in `require'
from (irb):4
irb(main):005:0> Haml.init_rails
NameError: uninitialized constant Haml
from (irb):5
from :0
irb(main):006:0>

Nathan Weizenbaum

unread,
Jul 1, 2008, 7:47:54 PM7/1/08
to ha...@googlegroups.com
require may return false, but it shouldn't throw an exception. Don't
forget to require rubygems first, though.

Jay

unread,
Jul 3, 2008, 6:45:23 AM7/3/08
to Haml
Hmm.

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'haml'
=> true
irb(main):003:0>

So it seems the problem is that I can require the gem from irb but not
from within the app. I'll continue checking and report back with what
I find. Thanks again for your help.

Jay

unread,
Jul 6, 2008, 3:56:05 PM7/6/08
to Haml
The problem here was so idiotic that I hesitate to post it, but I said
I would so here it is:

I had an older haml directory in plugins. I had named it something
different for some reason that is a mystery to me. So my situation
was this:

/vendor
/plugins
/haml
/stupidly_named_folder_with_old_version_of_haml

I took out the other folder and voila.

Nathan, thanks for your help.
Reply all
Reply to author
Forward
0 new messages