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

29 views
Skip to first unread message

Mislav Marohnić

unread,
Dec 20, 2008, 10:53:15 AM12/20/08
to Rails core
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?

Joshua Peek

unread,
Dec 20, 2008, 11:08:27 AM12/20/08
to Ruby on Rails: Core
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.

On Dec 20, 9:53 am, "Mislav Marohnić" <mislav.maroh...@gmail.com>
wrote:
> Josh Peek recently commitedhttp://github.com/rails/rails/commit/148aff2097890a81e874a7c60bae5fa3..."Set

Joshua Peek

unread,
Dec 20, 2008, 11:37:53 AM12/20/08
to Ruby on Rails: Core
Reply all
Reply to author
Forward
0 new messages