Instance variable won't update using basic Ajax script

I have been beating my head against the wall on this for days. It seems
that I can’t get an instance variable to update using Ajax if it
contains an array.
If the instance variable contains a singular value, my Ajax update works
fine.

In this instance, @listcount contains a number here and works fine:

<%= periodically_call_remote( :update => "counter",:frequency => 2,:url
=> { :action => :update_counter }) %>
<div id="counter"><%= @listcounts %></div>

In this next case, @trap contains an array that I have to iterate
through in my view and will not update using Ajax:

[code]
<%= periodically_call_remote( :update => “status”,:frequency => 2,:url
=> { :action => :update_data }) %>

<% even_odd = 0 for trap in @trap even_odd = 1 - even_odd %> <%=trap.datetime %> <%=trap.description %>

Can anyone point me in the right direction to get @trap to update using
Ajax?

Here is the controller code for @trap:

def update_data
        @trap = Trap.find(:all, :order => "datetime DESC")
        render :text => @trap
end

Any and all suggested will be treated as gold :slight_smile:
thanks

jackster.mobi

damn strait you can’t do that

<%= render :partial => 'status', :locals => {:traps => @trap} %>

:partial => status:

<% even_odd = 0 traps.each do |trap| even_odd = 1 - even_odd %>
<%=trap.datetime %> <%=trap.description %>

def update_data
@trap = Trap.find(:all, :order => “datetime DESC”)
render :partial => ‘status’, :locals => {:traps => @trap}
end

thanks alot for the help Keynan…I NEVER would have guessed the syntax
on that. I googled this problem for hours and found no documentation
worth anything. I put in the code you suggested, but am getting errors.

I am gettting an error in my view:

     wrong number of arguments (0 for 3)

it doesn’t like the following line:

  <%= render :partial => 'status', :locals => {:traps => @trap} %>

It might be a mistake on my interpretation of your instructions, here’s
what I have in my config based on your advice:
------------begin view ---------------------------
<%= periodically_call_remote( :update => “status”,:frequency => 2,:url
=> { :action => :update_data }) %>

:partial => status:
<%= render :partial => 'status', :locals => {:traps => @trap} %>
 
<% even_odd = 0 traps.each do |trap| even_odd = 1 - even_odd %> <% end %>
<%=trap.datetime %> <%=trap.desc1 %>
----------------end view -------------------------- ----------------begin controller ------------------ def update_data @trap = Trap.find(:all, :order => "datetime DESC") render :partial => 'status', :locals => {:traps => @trap} end ---------------end controller----------------------- I really appreciate the help on this....thanks.

jackster

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