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

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.