rails/rails — pull request #8406 by rwz (2012-12-03 17:19:00+00:00)
Title: ActionView::Template#refresh fails to reload the template to render the error

Sorry, I messed up with previous issue (#8383) by submitting pull-request on the wrong base :(

I'm trying to render a json/jbuilder template inside of a regular html template. Here is the code of the helper I'm using

```ruby
def get_some_json_stuff
render partial: 'my_json_partial', handler: [:jbuilder], formats: [:json], locals: { foo: @bar }
end
```

Everything goes fine in most cases, the template renders and I'm getting a string of json — exactly what I want.

But when there is an exception in the json template, funny things start to happen. Basically, I'm seeing this description:

```
Missing partial /my_json_partial with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :jbuilder, :coffee]}. Searched in:
* "/my/app/views"
```

I've looked into actionpack in attempt to understand what's going on and here's what I've found.

The code goes into [render method](https://github.com/rails/rails/blob/v3.2.9/actionpack/lib/action_view/template.rb#L142) then the error actually happens and gets rescued by [handle_render_error ](https://github.com/rails/rails/blob/v3.2.9/actionpack/lib/action_view/template.rb#L310) method.

And then it comes to [refresh](https://github.com/rails/rails/blob/v3.2.9/actionpack/lib/action_view/template.rb#L163) method that actually tries to reload the broken template. Doing so, it completely ignores original template format and handler, trying to use view's defaults, therefore failing and showing completely unrelevant exception.