# Trouble trying rjs

**URL:** <https://www.ruby-forum.com/t/trouble-trying-rjs/175204>\
**Category:** Rails\
**Created:** [September 9, 2009, 5:54pm UTC](https://www.ruby-forum.com/t/trouble-trying-rjs/175204 "2009-09-09T17:54:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bouldr-matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@bouldr-matt](https://www.ruby-forum.com/u/bouldr-matt)\
**Post date:** [September 9, 2009, 5:54pm UTC](https://www.ruby-forum.com/t/trouble-trying-rjs/175204/1 "2009-09-09T17:54:50Z")

</div>

Hi guys,

I’ve done a tiny bit of ajax before, but now I’m trying out rjs  
templates  
and functions.

I’m trying to re-create something like [http://live.lmgtfy.com](http://live.lmgtfy.com) with  
periodically\_call\_remote. The problem is when I try to use an rjs  
template,  
or rjs in the controller.

I’ve got a controller action that pulls a record from the database, sets  
the  
‘seen’ flag and then attempts to append the body of the record to a  
list.

The rjs template looks like this:

update\_page do |page|  
page.insert\_html :bottom, ‘content’, “

- #{@quote}
”  
end

And if I try it from the controller it looks like this:

render :update do |page|  
page.insert\_html :bottom, ‘content’, “

- #{@quote}
”  
end

Either way it seems to fail to output the appropriate JS and instead  
outputs:

try {  
} catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(‘’); throw e  
}

This happens no matter what I try to get the JS to do. If I just write  
the  
record to the view (ie have it completely replace the list rather than  
append to it) it works perfectly.

The idea is that when the remote call happens it should append the quote  
to  
the list, or, if there is no unread quote waiting, it should just do  
nothing. Right now I’d just like it to append and I’ll work on the  
conditional later.

Am I missing something with RJS? I’m not sure if I’ve explained myself  
very  
well, so please ask for clarification if necessary.

Many thanks

Matt

---

<div class="post-metadata">

**Author:** ![bouldr-matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@bouldr-matt](https://www.ruby-forum.com/u/bouldr-matt)\
**Post date:** [September 9, 2009, 6:04pm UTC](https://www.ruby-forum.com/t/trouble-trying-rjs/175204/2 "2009-09-09T18:04:47Z")

</div>

On Wed, Sep 09, 2009 at 04:53:13PM +0100, Matt H. wrote:

> try {  
> } catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(’’); throw e }

I’m sorry for the line noise, I seem to have found the problem. It  
ocurred  
to me that both the periodically\_call\_remote and the rjs were both  
specifying what to change. I removed the :update param from the  
remote\_call  
and now it seems to be working fine.

Now I just need to work on the fancy scroll effect that they use 🙂

Matt

---

<div class="post-metadata">

**Author:** ![bouldr-matt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@bouldr-matt](https://www.ruby-forum.com/u/bouldr-matt)\
**Post date:** [September 16, 2009, 11:39am UTC](https://www.ruby-forum.com/t/trouble-trying-rjs/175204/3 "2009-09-16T11:39:45Z")

</div>

Hi Matt,

I am also trying to achieve something like [http://livingsocial.com](http://livingsocial.com), I  
went through your topic and found that you’ve solved the same problem…  
Can you help me with some code… here is what I’ve done so far.

##ajax\_call.rhtml

\<% @products = Product.find(:all, :limit =\> 50, :order =\> “id DESC”) %\>  
\<% for product in @products %\>  
\<%= periodically\_call\_remote(:url =\> {:action =\> “time”, :id =\>  
product.id}, :frequency =\> 5.0, :update =\> ‘product\_div’) %\>  
\<% end %\>

##controller  
def time  
@product = Product.find(params[:id])  
end

##time.rhtml

## Current Product is: \<%=h @product.product\_name %\>

The problem is it is continuously overwriting the div, where as I want  
the list to come. Please help me with some code

Thanks  
Puneet

Matt H. wrote:

> On Wed, Sep 09, 2009 at 04:53:13PM +0100, Matt H. wrote:
> 
> > try {  
> > } catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(‘’); throw e }
> 
> I’m sorry for the line noise, I seem to have found the problem. It  
> ocurred  
> to me that both the periodically\_call\_remote and the rjs were both  
> specifying what to change. I removed the :update param from the  
> remote\_call  
> and now it seems to be working fine.
> 
> Now I just need to work on the fancy scroll effect that they use 🙂
> 
> Matt
