V
voice10
Hi all, It must be a very simple solution, but i'm just not getting it.
I want to display some picture continously on a page using Rail+AJAX.
Here is the snippet of code:
Controller
------------------------
def show
@albums = Album.find
all)
@size = @albums.length
end
def show_next
@id = params[:cur_id].to_i
@size = params[:max].to_i
if ( @id == 0 or ir @id > @size)
@id = 1
end
@album = Album.find(@id)
@id += 1
end
show.rhtml
-------------------------------------
<html>
<body>
Continous picture display<br>
<%= periodically_call_remote
update => 'mydiv',
:url => { :action => :show_next,
:cur_id => @id, :max => @size},
:frequency => 2 )
<div id="mydiv">
image will display here
</div>
</body>
</html>
show_next.rhtml
-------------------------------------
def show_next
<img width="600" height="200" src="<%= @album .image_url %>"/>
end
------------------------------------------------------------------------------------------------------------------
But the @id is not being updated. I think I need to store the @id
statically in the html page (may as hidden field), but is there any
better solution for this
thanks in avdvance
/Rick
I want to display some picture continously on a page using Rail+AJAX.
Here is the snippet of code:
Controller
------------------------
def show
@albums = Album.find
@size = @albums.length
end
def show_next
@id = params[:cur_id].to_i
@size = params[:max].to_i
if ( @id == 0 or ir @id > @size)
@id = 1
end
@album = Album.find(@id)
@id += 1
end
show.rhtml
-------------------------------------
<html>
<body>
Continous picture display<br>
<%= periodically_call_remote
:url => { :action => :show_next,
:cur_id => @id, :max => @size},
:frequency => 2 )
<div id="mydiv">
image will display here
</div>
</body>
</html>
show_next.rhtml
-------------------------------------
def show_next
<img width="600" height="200" src="<%= @album .image_url %>"/>
end
------------------------------------------------------------------------------------------------------------------
But the @id is not being updated. I think I need to store the @id
statically in the html page (may as hidden field), but is there any
better solution for this
thanks in avdvance
/Rick