TemplateError for second-level partial during AJAX update

Hi All,

Could someone please explain to me why I’m getting an
ActionView::TemplateError when I try to use AJAX to update the
interface while using the following code:

  <div id="building[<%=building.id%>][controls]">
<%building.controls.each do |control|%>
  <%=render :partial => "control", :locals => {:control => 

control}%>
<%end%>

I have the following structure: Site -> Building -> Control. Each
loops through it’s collection of items and renders a partial for
each. From Site to Building works just fine. However, going from
Building on to Control throws the template error.

It is noteworthy that Controls get added just fine, and if I refresh
the page, all the code works – but for some reason when I try to do
the AJAX thing, the partial (not the “rjs” file) throws an error.

Any thoughts? My apologies if this is too vague.

Best.

check the location of template . this may be cause .

N A R E N

My apologies. Actually the error is that there is no method named
‘controls’. In fact, this is the full error:

ActionView::TemplateError (undefined method `controls’ for #<Control:
0x21f61f0>) on line #21 of app/views/site_manager/_building.html.erb:
18:
19:
20:


21: <%for control in building.controls%>
22: <%=render :partial => “control”, :locals => {:control =>
control}%>
23: <%end%>
24:

app/views/site_manager/_building.html.erb:21
app/views/site_manager/add_control_to_building.rjs:1:in

__instance_exec0' app/views/site_manager/add_control_to_building.rjs:1:in _run_rjs_app47views47site_manager47add_control_to_building46rjs’
app/controllers/site_manager_controller.rb:23:in
`add_control_to_building’

Rendered rescues/_trace (56.4ms)
Rendered rescues/_request_and_response (1.5ms)
Rendering rescues/layout (internal_server_error)

On Jun 16, 2:33 am, Narendra sisodiya [email protected]

check for
<%for control in building.controls%>

and make sure controls is defined

~N A R E N

Wow! Yeah, I was aware of what rails thought was the issue, but I
was also sure I was in the right. Turns out I was wrong. I’d copied
and pasted the “rjs” code into the new “rjs” file. When I did, I
missed the partial name and left it as “building”, so it was passing a
“control” object back to the “building” partial when it should have
been passing it to the “control” partial. Thanks so much for letting
me talk out loud!

On Jun 16, 5:14 am, Narendra sisodiya [email protected]

You seem to have Control object itself stored in building variable and
hence
it does not have any controls method in it

On Tue, Jun 16, 2009 at 1:39 PM, gberz3 [email protected] wrote:

21: <%for control in building.controls%>
`_run_rjs_app47views47site_manager47add_control_to_building46rjs’

check the location of template . this may be cause .

ActionView::TemplateError when I try to use AJAX to update the
loops through it’s collection of items and renders a partial for

  • NAYAK