title: ajax render template versus partial stack level error
body: <p>Been away from rails for about a year and trying to remember everything by experimenting with a prototype. I inherited the scaffold template to provide a Show view that allows drilling down to related has_many models.There are some deeply nested models but I never go more that 1 deep and use the show view to drill down.</p>
  
  <pre><code>fieldset
      show fields from models
      actions on model
  related action menubar (links to load related records with js)
  fieldset
      related index view
  </code></pre>
  
  <p>By default, the primary related models index view is rendered as a template from the show view, often from the index.html.erb of the related model. Using routing, most of the related index views can also be rendered on its own page. I did about 8 models using this scheme, but the last one I tried gave me a <code>ActionView::Template::Error (stack level too deep):</code> error trying to load the .js template hundreds of times and never loading the template called for in the .js file.</p>
  
  <pre><code>Started GET "/events/2/participants" for 127.0.0.1 at 2012-11-21 05:39:56 -0600
  Processing by EventsController#participants as JS
    Parameters: {"id"=&gt;"2"}
    Event Load (0.1ms)  SELECT "events".* FROM "events" WHERE "events"."id" = ? LIMIT 1  [["id", "2"]]
    Rendered events/participants.js.erb (0.2ms)
    Rendered events/participants.js.erb (1.9ms)
    ...  
    Rendered events/participants.js.erb (486.2ms)
    Rendered events/participants.js.erb (487.6ms)
  Completed 500 Internal Server Error in 496ms
  
  ActionView::Template::Error (stack level too deep):
    activesupport (3.2.8) lib/active_support/notifications/instrumenter.rb:23
  </code></pre>
  
  <p>A working controller actions and the .js line:</p>
  
  <pre><code>def stages
    @commitment = Commitment.find(params[:id])
    @stages = @commitment.stages.page(params[:page]).per(10)
    respond_to do |format|
      format.js 
      format.html {render :template =&gt; "stages/index"}
    end
  end
  
  &lt;stages.js.erb&gt;
  $("#related").html("&lt;%= escape_javascript(render(:template =&gt; 'stages/index'))%&gt;");
  </code></pre>
  
  <p>Notice the .js file renders the template from the stages view.</p>
  
  <p>The same stuff for the controller that gave me a problem:</p>
  
  <pre><code>def participants
    @event = Event.find(params[:id])
    @participants = @event.participants
    respond_to do |format|
      format.js 
      format.html {render :template =&gt; "events/participants"}
    end
  end
  
  &lt;participants.js.erb&gt;
  $("#related").html("&lt;%= escape_javascript(render(:template =&gt; 'events/participants'))%&gt;");
  </code></pre>
  
  <p>The only difference is that the index is in the Events view (no Participants views/controllers). The default template will load without the render hash on format.html, but left it to be consistent.</p>
  
  <p>After scratching my head for a few hours trying to find any other differences. I made participants.html.erb a partial and changed the .js line to </p>
  
  <p>$("#related").html("&lt;%= escape_javascript(render(:partial => 'events/participants'))%>");</p>
  
  <p>That worked, no errors, both js and html work(participants.html.erb renders partial)!</p>
  
  <p>Since I got it working I guess I don't have a question other than why the different behavior for a template versus a partial? Or, is there something else I need to learn?</p>
  
  <p>Steve</p>