Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

UJS & partial possible bug

#5682

Hi,

I'm new to rails, so this might be my fault instead of a bug. But at least it sounds odd. Here are a few files:

list.html.erb

<table>
<% @boxes.each do |box| %>
  <tr>
    <td><%= box.name %></td>
  </tr>
<% end %>
</table>
<div id="add">
  <%=
    render :partial => "list_add"
  %>
</div>

_list_add.html.erb

<%=
  link_to_function("add a new box") do |page|
    page.replace_html "add", :partial => "list_new"
  end
%>

_list_new.html.erb

<%=
  link_to_function("finished adding a new box") do |page|
    page.replace_html "add", ":partial => list_add"
  end
%>

This code crashes the WEBrick server when trying to render list.html.erb:

macbook-pro-de-philippe-lang:attikdb plang$ rails s
=> Booting WEBrick
=> Rails 3.0.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2010-09-22 11:09:56] INFO  WEBrick 1.3.1
[2010-09-22 11:09:56] INFO  ruby 1.9.2 (2010-08-18) [x86_64-darwin10.4.0]
[2010-09-22 11:09:56] INFO  WEBrick::HTTPServer#start: pid=2959 port=3000
Illegal instruction
macbook-pro-de-philippe-lang:attikdb plang$

Browser says:

Erreur 324 (net::ERR_EMPTY_RESPONSE) : Erreur inconnue

A small change and the server does not crash anymore:

_list_new.html.erb

<%=
  link_to_function("finished adding a new box") do |page|
    page.replace_html "add", "rendering list_add partial here..."
  end
%>

It looks like rails does not like partials rendering each other through UJS.

What I'm trying to acomplish here is some kind of web 2.0 in-place editing at the bottom of a list. There might be a better way of doing that, sure!

My config: ruby 1.9.2, rails 3.0.0

Reported by Philippe Lang · September 22nd, 2010 @ 10:33 AM

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Marjan Krekoten'
    Marjan Krekoten'

    Well I maybe wrong but your code just enters infinite loop. _list_add.html.erb and _list_new.html.erb render each other until ruby crashes.

    September 22nd, 2010 @ 09:44 PM

  2. Philippe Lang
    Philippe Lang
    • Tag changed from illegal response, partial, ujs to illegal instruction, partial, ujs

    Hi Marjan,

    Each partial renders the other, but only after a click, since "link_to_function" is used. This shouldn't be a problem as far as I understand. But you are right, there must be some kind of infinite loop inside the framework.

    September 23rd, 2010 @ 07:04 AM

  3. Marjan Krekoten'
    Marjan Krekoten'

    It renders partials on server side. JS code on clients side operates with already rendered strings. So while rendering those partials are trying to render each other.

    September 23rd, 2010 @ 07:11 AM

  4. Philippe Lang
    Philippe Lang

    When rendering list.html.erb, I thought that only the _list_add.html.erb partial was rendered, with a link allowing the rendering of the next partial through UJS, and so on. Conceptually, I have to admit I still don't see exactly why this code breaks...

    September 23rd, 2010 @ 07:21 AM

  5. Philippe Lang
    Philippe Lang

    Hum, I think I understand better now. As you say "JS code on clients side operates with already rendered strings". That means rails tries to pre-render both partials rendering each other, UJS or not, resulting in an infinite loop. I could see that with a few puts added at the top of the partials:

    ------> rendering new
    ------> rendering add
    ------> rendering new
    ------> rendering add
    ------> rendering new
    ------> rendering add
    ------> rendering new
    ------> rendering add
    ------> rendering new
    ------> rendering add
    ------> rendering new
    ------> rendering add
    ------> rendering new
    ------> rendering add
    ------> rendering new
    ------> rendering add
    ------> rendering new
    ------> rendering add
    ------> rendering new
    Illegal instruction
    

    So I guess this is not a bug at all: rails certainly works like this "by design".

    September 23rd, 2010 @ 08:50 AM

  6. David Trasbo
    David Trasbo
    • State changed from new to invalid
    • Importance changed from to Low

    See above.

    September 25th, 2010 @ 06:18 PM