# Caching RJS fragments

**URL:** <https://www.ruby-forum.com/t/caching-rjs-fragments/148612>\
**Category:** Rails\
**Created:** [September 15, 2008, 4:34pm UTC](https://www.ruby-forum.com/t/caching-rjs-fragments/148612 "2008-09-15T16:34:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![overclokkato](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c67d28/32.png) [@overclokkato](https://www.ruby-forum.com/u/overclokkato)\
**Post date:** [September 15, 2008, 4:34pm UTC](https://www.ruby-forum.com/t/caching-rjs-fragments/148612/1 "2008-09-15T16:34:08Z")

</div>

Do you have any hint for using fragment caching within a RJS response?  
I’ve the following piece of code in a rjs template

for hotel in @hotels  
cache(:id =\> hotel.id, :format =\> params[:format]) do  
page.insert\_html(:bottom, :items, :partial =\> hotel, :locals =\>  
{ :city =\> @city, :country =\> @country })  
end  
end

but when the response is rendered it returns the following error,  
probably because cache expects an ERB template.

ActionView::TemplateError (undefined local variable or method  
`\_erbout’ for #ActionView::Base:0x20b8e00) on line #2 of hotels/  
index.js.rjs:

I searched the newsgroup and I read thousand of blog posts but I  
haven’t been able to figure out a reasonable solution.  
Any suggestion?
