Edge Rails rendering partials on XHR requests change: breakage or intended?

Josh Peek recently commited http://github.com/rails/rails/commit/148aff2097890a81e874a7c60bae5fa3b2a4d1fd

“Set template_format to html inside rjs templates so renders within it default to html.”

This broke controller actions like this:

def show

render :partial => ‘item’ if request.xhr?

end

This action would render default template on ordinary requests and a “_item.html.erb” partial on XHR requests.

After this commit, if there’s an XHR request this raises an exception that “_item.erb” can’t be found. It probably discards the “html” format template because the request is in “js” format. Workarounds are these:

def show

respond_to do |format|

format.html { render :partial => ‘item’ if request.xhr? }

end

end

or:

def show

@template.template_format = ‘html’

render :partial => ‘item’ if request.xhr?

end

Both of these make sense because they kinda explicitly state that they don’t care if the request was “js” format, they will respond in “html” anyway.

So my question is, was this breakage deliberate? Was the way I rendered HTML partials before wrong?

Not intentional.

I didn't really think of this case, the test I removed showed a stupid
use case of rendering it with an inline.

I'm interesting in fixing this, but I'd rather not restore the hack in
ActionView. This logic should be in ActionController.

Please do ticket me and we'll eventually sort this out.

I can't think of a good clean way to extend the format picking logic
right now. I kind of feel like the XHR request should be saying "Give
me HTML plz!". Dunno if thats possible or a good idea.

Someone already reported it:

http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1590-xhrs-require-explicit-respond_to#ticket-1590-2

Please comment there.