I am trying to split my HAML view to the separate files. I have read the Sinatra Book and tried to implement the basic version.
So I have created app_helpers.rb file:
# Usage: partial :foo
helpers do
def partial(page, options={})
haml page, options.merge!(:layout => false)
end
end
And require it in my application.rb:
require 'sinatra'
require_relative './app_helpers.rb'
Then I have created partial views/test.haml:
<h3> Test message </h3>
And require it in my index.haml:
= partial :test
But when I refresh my page I get the error message:
NoMethodError - undefined method `partial' for #<Application:0x514dbe0>:
c:/Dropbox/development/myprojects/test/sinatra-bootstrap/views/index.haml:27:in `evaluate_source'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/tilt-1.3.3/lib/tilt/template.rb:209:in `instance_eval'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/tilt-1.3.3/lib/tilt/template.rb:209:in `evaluate_source'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/tilt-1.3.3/lib/tilt/template.rb:144:in `cached_evaluate'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/tilt-1.3.3/lib/tilt/template.rb:127:in `evaluate'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/tilt-1.3.3/lib/tilt/haml.rb:24:in `evaluate'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/tilt-1.3.3/lib/tilt/template.rb:76:in `render'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/sinatra-1.3.1/lib/sinatra/base.rb:625:in `render'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/sinatra-1.3.1/lib/sinatra/base.rb:522:in `haml'
How can I fix it?
Updated:
All works fine if I rewrite app_helpers.rb such way:
def partial(page, options={})
haml page, options.merge!(:layout => false)
end
What is the reason of this?