# RJS - ActionView::TemplateError (page)

**URL:** <https://www.ruby-forum.com/t/rjs-actionview-templateerror-page/188360>\
**Category:** Rails\
**Created:** [May 10, 2010, 9:48pm UTC](https://www.ruby-forum.com/t/rjs-actionview-templateerror-page/188360 "2010-05-10T21:48:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kmiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/3ec8ea/32.png) [@kmiller](https://www.ruby-forum.com/u/kmiller)\
**Post date:** [May 10, 2010, 9:48pm UTC](https://www.ruby-forum.com/t/rjs-actionview-templateerror-page/188360/1 "2010-05-10T21:48:54Z")

</div>

Without going into too much detail, is there something obvious that I’m  
missing here? It seems to be finding the RJS file as expected but  
generates this error:

ActionView::TemplateError (undefined local variable or method `page’ for  
#ActionView::Base:0x7f202a04) on line #1 of  
app/views/fuelings/index.js.rjs:  
1: page.toggle ‘fuelings’

```
app/views/fuelings/index.js.rjs:1:in

```

`_run_rjs_app47views47fuelings47index46js46rjs' app/views/fuelings/index.js.rjs:1:in`\_run\_rjs\_app47views47fuelings47index46js46rjs’  
app/controllers/fuelings\_controller.rb:6:in `index’

The general outline (without posting too much code) is:

1. Index action in the controller has a respond\_to that invokes  
index.js.rjs
2. The index view has an observe that triggers when the select changes
3. The RJS renders a partial (not implemented yet)

Also set up a skeleton rails app just to test RJS and am getting the  
same thing when I try any RJS tests.

==========================  
Controller:

class FuelingsController \< ApplicationController  
def index  
@vehicles = Vehicle.find(:all)  
@vehicle = params[:vehicle\_id] ?  
Vehicle.find\_by\_id(params[:vehicle\_id]) : Vehicle.find(:first)  
@fuelings = @vehicle.fuelings.paginate(:all,:per\_page =\> 15,  
:page =\> params[:page])  
respond\_to do |format|  
format.html  
format.js  
end  
end

==========================  
View:

\<% javascript :defaults %\>  
\<% title “Fuelings for: #{@vehicle.license}” %\>  
\<% form\_tag “”, :url =\> fuelings\_path, :method =\> :get do %\>  
\<%= select\_tag  
“vehicle\_id”,options\_for\_select(@vehicles.collect{|v|[v.license,v.id]},@vehicle.id)  
%\>  
\<%= observe\_field(“vehicle\_id”,  
:url =\> { :action =\> :index },  
:method =\> :get,  
:with =\> ‘vehicle\_id’,  
:on =\> “changed”) %\>  
\<% end %\>

 \<%= render :partial =\> "fuelings" %\>
\<%= will\_paginate @fuelings %\>

==========================  
RJS: (just to test)  
page.toggle “fuelings”

---

<div class="post-metadata">

**Author:** ![kmiller](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/3ec8ea/32.png) [@kmiller](https://www.ruby-forum.com/u/kmiller)\
**Post date:** [May 11, 2010, 1:57am UTC](https://www.ruby-forum.com/t/rjs-actionview-templateerror-page/188360/2 "2010-05-11T01:57:39Z")

</div>

Hi Kurt,

On Mon, May 10, 2010 at 2:48 PM, Kurt M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Without going into too much detail, is there something obvious that I’m  
> missing here?

The only thing that jumps out at me is the lack of a block after your  
format…

Try adding it: format.js {}

If that doesn’t work, add try getting rid of the rjs template for now  
and  
just render from the contoller. Generally speaking, that’s preferable  
for a  
one-liner anyway.

format.js {  
render :update do |page|  
page.toggle ‘fuelings’  
end  
}

HTH,  
Bill
