Hi,
I am trying to have a thread updating information in the @session
variable and an AJAX call to display these updates to the user.
The source code will make things easier to explain:
<!-- view: search.rhtml -->
<%= periodically_call_remote(
:update => ''listing'',
:position => :after,
:url => {:action => :getStream},
:frequency => 10)
%>
against this controller code:
#app/controller/search_controller.rb
...
def search
@session[:stream] = Array.new unless @session[:stream]
@baseUrl = params[:post][''url'']
a = Thread.new {
IO.popen("perl script/findStream_bsf.pl #{@baseUrl}") { |f|
while (f.gets) do
logger.log "adding stream to array"
@session[:stream].push(''$_'')
end
}
}
end
def getStream
if @session[:stream].length > 0
render(:text => "#{@session[:stream].length} stream(s) found
<br/>")
else
render(:text => ''no stream found <br/>'')
end
end
...
The odds are that even if the logger logs ''adding stream to
array'',
getStream never sees that, and keep on rendering ''no stream
found''.
It seems that the problem is with a thread updating @session: has
someone had the same peoblem before?
Or am I missing some basic concept with @session here?
Cheers
/giulio