views:

106

answers:

1

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:

CODE

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.

EDIT -- The error is as follows: TEMPLATE ERROR

A: 

Let's deconstruct the error you get:

ActionView::TemplateError (undefined method `controls' for #) on line #21 of app/views/site_manager/_building.html.erb

The first part ActionView::TemplateError is just the type of exception raised and not really interesting in this case. The next part is, however:

undefined method `controls' for #<Control:0x21f61f0>

This basically tells you that you're trying to call a method called controls on an object that's an instance of the Control model. It also tells you that the controls method is not defined on that instance.

on line #21 of app/views/site_manager/_building.html.erb

The above tells you where to find the source of this error, namely line 21 in the site_manager/building partial. That line looks like:

<%for control in building.controls%>

In that line you're trying to call a controls method on a variable, which is what isn't working according to the error message; the controls method is undefined on that variable. The error message also told you that the variable contains an instance of your Control model.

Now, you've named the variable building, but it contains an instance of Control, which leads me to believe that you've somehow put another value into the building variable than you intended.

Unfortunately, you don't show the code that assigns the value to the building variable, so I can't get any closer to a real answer for you. Hopefully the above is enough to lead you to a solution.

Jakob S
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!
humble_coder