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’, “

  • #{@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

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

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

    Matt

    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs