0

I have come across a issue when writing some sinatra code I have the follow block of code

begin
    # do stuff here 
rescue SomeException::Class => ex
  flash.now[:err] = "some error " + ex.message
ensure
  erb :content, :layout => :mainlayout 
end

The problem I have is the erb output is only partially rendered, mainlayout.erb is rendered, however, content.erb doesn't get included. I have used the same erb line in other parts of the application and they work fine.

The following actually works and is a work around that I am currently using

    begin
      # do stuff here 
      erb :content, :layout => :mainlayout 
    rescue SomeException::Class => ex
      flash.now[:err] = "some error " + ex.message
      erb :content, :layout => :mainlayout 
    end 

Any ideas to why this isn't completing when under ensure? I would like to use it as its more elegant.

  • 1
    try to use return erb :content, :layout => :mainlayout read more about `ensure` here - http://blog.leshill.org/blog/2009/11/17/ensure-with-explicit-return.html – Vasiliy Ermolovich Jun 03 '11 at 16:11
  • @mu is too short - As I stated in the original post erb is getting called, therefore ensure is working. the problem is that the content.erb is not rendering into the mainlayout.erb therefore all the html that should be generated from content.erb is missing but not the html in mainlayout.erb. Its really confusing because the same erb line works fine outside ensure. Something is blocking the partial from rentering. –  Jun 03 '11 at 18:39
  • @nash I will try that and report back –  Jun 03 '11 at 18:42
  • @nash yes that was the issue it must have been bombing out on the first return it found in the erb lib or something like that. If you would like to add a proper answer I will award it as best answer. Thank you. –  Jun 03 '11 at 18:49

1 Answers1

1

try to use return erb :content, :layout => :mainlayout read more about ensure here - http://blog.leshill.org/blog/2009/11/17/ensure-with-explicit-return.html

Vasiliy Ermolovich
  • 24,459
  • 5
  • 79
  • 77