In my never ending quest to avoid doing anything useful, I decided to attempt to run Sinatra on top of JRuby. I had the original goal of getting it to run under JRuby-Rack and built into a war file that Tomcat or JBoss, or Weblogic, or… Glassfish(??) would take. Unfortunately, I didn’t get that far. What I saw was:
LocalJumpError - yield called out of block
My mini application that shows the issue:
$:.unshift File.dirname(__FILE__) + '/sinatra/lib' require 'sinatra' get '/' do "Hello World" end get '/no_layout' do erb :foo, :layout => false end get '/erb' do erb :foo end get '/haml' do haml :foo end
Of course I have some views: - (just erb here, hamls are almost identical)
<!-- this is foo.erb --> <p>Erb rendered</p> <!-- this is layout.erb --> <html> <head></head> <body> <p>Layout rendered</p> <%= yield %> </body> </html>
So… I filed a bug report against JRuby.. I’m impressed that Vladimir has already identified the narrow test case that I didn’t, and has written specs. I’m hoping that the next release of JRuby will have this fixed, and we can all move on with our lives.
Until then, layouts in Sinatra don’t work with JRuby.