views:

1213

answers:

2

Hello

I try to get haml working without the gem with sinatra (Heroku doesn't allow gem install, as far as I know)

What I've done so far:

  • clone the haml git repo inside my project

  • add : require 'haml/lib/haml.rb' to my sinatra main file

the following works:

get '/test' do
  Haml::Engine.new('%p test').render
end

but the following doesn't:

get '/test2' do
  haml :my_template
end

I get the error :

NoMethodError - undefined method each' for nil:NilClass (haml):20:in render'

./haml/lib/haml/engine.rb:152:in `render'

./haml/lib/haml/engine.rb:152:in `instance_eval'

./haml/lib/haml/engine.rb:152:in `render' ...

Is there any other files to require ? Any ideas ?

+2  A: 

The two most obvious possibilities (in order of probability):

  1. There's an error in some Ruby code in your Haml file. If you can try the same code outside of Sinatra, does it render OK there?
  2. The file my_template.haml is either not there or incorrectly named.
Chuck
thanks, I had @results.each where @results is nil in my haml file
Gaetan Dubar
+5  A: 

Heroku supports installing gems by creating a .gems file in your project's root directory and adding it to Git. On your next push the gems required in there will be installed. To install Haml the file would contain this line:

haml --version '>= 2.2.0'

More information can be found here: http://docs.heroku.com/gems

petergassner