JRuby

Sinatra Web Framework fails on rendering ERB while MRI works - LocalJumpError - yield called out of block

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: JRuby 1.1.3
  • Component/s: Core Classes/Modules
  • Labels:
    None
  • Environment:
  • Number of attachments :
    1

Description

See the Sinatra bug report at: http://sinatra.lighthouseapp.com/projects/9779/tickets/24-running-on-jruby-fails-at-rendering-erb-templates

Copied from the original bug report:

The sinatra app (app.rb):

require '../sinatra/lib/sinatra.rb'

get '/' do
"Hello World"
end

get '/:foo' do
erb :foo
end

The template (views/foo.erb):

<html>
<head></head>
<body>Erb rendered</body>
</html>

The command to run the application:
jruby app.rb

The error:

Params:

{"foo"=>"blah"}

LocalJumpError - yield called out of block

The working part:
Going to '/' returns "Hello World" just as expected. Using a Haml renderer works fine as well.

Issue Links

Activity

Hide
Chris Schneider added a comment -

On further investigation, it appears I have a rouge layout in the views directory that I didn't notice. I only had one for erb, and not for haml, which mislead me to think that Erb was the problem.

It appears that layouts in general are the issue, and not erb, haml or any other particular renderer. The error remains the same.

views/layout.erb
------
<html>
<head></head>
<body>
<p>Layout rendered</p>
<%= yield %>
</body>
</html>

views/layout.haml
------
%html
%body
#content= yield

views/foo.haml
--------
%p Hello World

Of course to change to using the haml renderer, you have to change the "erb :foo" line to "haml :foo".

Also, as a bit of background for people who haven't seen Sinatra before, basically, you map URLs to actions. The line "get '/:foo' do" sets up a handler for /foo, /bar, /baz and so on. The :foo part denotes a variable that can be accessed via params[:foo], this feature is not used here. I realize that there might be a bit of confusion by my repeated use of "foo".

Show
Chris Schneider added a comment - On further investigation, it appears I have a rouge layout in the views directory that I didn't notice. I only had one for erb, and not for haml, which mislead me to think that Erb was the problem. It appears that layouts in general are the issue, and not erb, haml or any other particular renderer. The error remains the same. views/layout.erb ------ <html> <head></head> <body> <p>Layout rendered</p> <%= yield %> </body> </html> views/layout.haml ------ %html %body #content= yield views/foo.haml -------- %p Hello World Of course to change to using the haml renderer, you have to change the "erb :foo" line to "haml :foo". Also, as a bit of background for people who haven't seen Sinatra before, basically, you map URLs to actions. The line "get '/:foo' do" sets up a handler for /foo, /bar, /baz and so on. The :foo part denotes a variable that can be accessed via params[:foo], this feature is not used here. I realize that there might be a bit of confusion by my repeated use of "foo".
Hide
Charles Oliver Nutter added a comment -

Would it be possible to get a small packaged app we can run to make repeat this failure?

Show
Charles Oliver Nutter added a comment - Would it be possible to get a small packaged app we can run to make repeat this failure?
Hide
Vladimir Sizikov added a comment -

OK, I've figured what's the problem. And indeed this is a JRuby issue with eval'ing 'yield' to the supplied block/binding.

See JRUBY-2605 for more detail.

Show
Vladimir Sizikov added a comment - OK, I've figured what's the problem. And indeed this is a JRuby issue with eval'ing 'yield' to the supplied block/binding. See JRUBY-2605 for more detail.
Hide
Chris Schneider added a comment -

An example sinatra application (including the edge sinatra library as of writing).

This does rely on mongrel to run, and haml to run the haml examples.

Just point ruby at thingy.rb and then point your browser at http://localhost:4567/erb or /haml to see the problem, and at /no_layout to see it work fine with no layout.

Show
Chris Schneider added a comment - An example sinatra application (including the edge sinatra library as of writing). This does rely on mongrel to run, and haml to run the haml examples. Just point ruby at thingy.rb and then point your browser at http://localhost:4567/erb or /haml to see the problem, and at /no_layout to see it work fine with no layout.
Hide
Charles Oliver Nutter added a comment -

JRUBY-2605 has been fixed, so hopefully this issue is soon to be resolved.

Show
Charles Oliver Nutter added a comment - JRUBY-2605 has been fixed, so hopefully this issue is soon to be resolved.
Hide
Vladimir Sizikov added a comment -

Indeed, as soon as eval thing was fixed, this is fixed as well, I verified that, and Sinatra now works just fine.

Show
Vladimir Sizikov added a comment - Indeed, as soon as eval thing was fixed, this is fixed as well, I verified that, and Sinatra now works just fine.

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: