trouble trying rjs

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 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', "<li class='quote'>#{@quote}</li>"
end

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

render :update do |page|
  page.insert_html :bottom, 'content', "<li class='quote'>#{@quote}</li>"
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

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 :slight_smile:

Matt

Hi Matt,

I am also trying to achieve something like 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 %>
<div id="product_div">
</div>

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

##time.rhtml
<h2>Current Product is: <%=h @product.product_name %></h2>

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 Harrison wrote: