jackster the jackle
2008-Jan-19  00:36 UTC
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:
[code]
<%= periodically_call_remote( :update => "counter",:frequency
=> 2,:url
=> { :action => :update_counter }) %>
<div id="counter"><%= @listcounts %></div>
[/code]
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 }) %>
<div id="status">
<% even_odd = 0
for trap in @trap
even_odd = 1 - even_odd %>
<tr class="background<%= even_odd %>">
<td><%=trap.datetime %></td>
<td><%=trap.description %></td>
</div>
Can anyone point me in the right direction to get @trap to update using
Ajax?
Here is the controller code for @trap:
[code]
def update_data
        @trap = Trap.find(:all, :order => "datetime DESC")
        render :text => @trap
end
[/code]
Any and all suggested will be treated as gold :-)
thanks
jackster.mobi
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Keynan Pratt
2008-Jan-19  00:43 UTC
Re: Instance variable won''t update using basic Ajax script
damn strait you can''t do that
<div id="status">
 <%= render :partial => ''status'', :locals => {:traps
=> @trap} %>
</div>
:partial => status:
<table>
<% even_odd = 0
traps.each do |trap|
even_odd = 1 - even_odd %>
<tr class="background<%= even_odd %>">
<td><%=trap.datetime %></td>
<td><%=trap.description %></td>
</tr>
</table>
def update_data
        @trap = Trap.find(:all, :order => "datetime DESC")
        render :partial => ''status'', :locals => {:traps
=> @trap}
end
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
jackster the jackle
2008-Jan-19  01:38 UTC
Re: Instance variable won''t update using basic Ajax script
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 }) %>
<table width="100%">
<tr class="background0">
<td> </td>
</tr>
:partial => status:
<div id="status">
<%= render :partial => ''status'', :locals => {:traps
=> @trap} %>
</div>
</table>
<table width="100%" border="0">
<% even_odd = 0
traps.each do |trap|
even_odd = 1 - even_odd %>
<tr class="background<%= even_odd %>">
<td><%=trap.datetime %></td>
<td><%=trap.desc1 %></td></tr>
<% end %>
</table>
----------------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
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---