session variables and threading.

Gnanavel
Sat, 10 Sep 2005 14:07:35 -0000

Hi All,

For my problem of updating status in the view, i tried the following :

Controller :
def status
        #@session[''status''] = rand(0).to_s
        @status = @session[''status'']
        render :partial => "status", :locals => { :status =>
@status }
end

def startstatus
        @t = Thread.new {
                10.times do |i|
                    @session[''status''] = rand(0).to_s
                    sleep 2;
                end
        }
end

My startstatus.rhtml looks like this

<%= javascript_include_tag "prototype" %>

    <%= render_component :action => "status" %>
    <%= periodically_call_remote(:url => { :action => :status },
                                 :frequency => 4,
                                 :update => ''update1'' )
%>


_status.rhtml (render via partial)

<%= @status %>...



However the value of the @session[''status''] does not chnage in
the view,
looks like the thread has been killed or something? I only get the firts
value and then on the value does not chnage every 4 secs.

Let me know what should I have to change for getting the value of the
session from the thread.

Regards
Gnan