# Rails AJAX question

**URL:** <https://www.ruby-forum.com/t/rails-ajax-question/65249>\
**Category:** Ruby\
**Created:** [February 10, 2006, 5:53am UTC](https://www.ruby-forum.com/t/rails-ajax-question/65249 "2006-02-10T05:53:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 10, 2006, 5:53am UTC](https://www.ruby-forum.com/t/rails-ajax-question/65249/1 "2006-02-10T05:53:35Z")

</div>

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
 Continous picture display  
 \<%= periodically\_call\_remote(:update =\> 'mydiv', :url =\> { :action =\> :show\_next, :cur\_id =\> @id, :max =\> @size}, :frequency =\> 2 ) 
 image will display here 

## show\_next.rhtml

def show\_next  
 ![]()  
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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 10, 2006, 6:15am UTC](https://www.ruby-forum.com/t/rails-ajax-question/65249/2 "2006-02-10T06:15:22Z")

</div>

On Friday 10 February 2006 01:53 pm, removed\_email\_address@domain.invalid wrote:

EWRONGMAILINGLIST

[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Tsume

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 10, 2006, 1:23pm UTC](https://www.ruby-forum.com/t/rails-ajax-question/65249/3 "2006-02-10T13:23:36Z")

</div>

I liked this tutorial, it has a nice example on the lack of memory of  
web applications

> **[Rapid Learning Rails](http://www.troubleshooters.com/codecorn/ruby/rails/rapidlearning_rails.htm)**
>
> Learn Rails fast

I have been working with a controller code as such  
if params.has\_key? :id  
@laststimobj=Stimuli.find(params[:id])  
@stimuliobj=Stimuli.find(params[:id].to\_i + 1)  
else  
@stimuliobj = Stimuli.find(:first)  
end

with a form in the view  
\<%= start\_form\_tag(:action =\> “hello”) %\>  
\<%= hidden\_field\_tag “id”, @stimuliobj.id %\>

Name: \<%= text\_field("responseobj", "name", "size" =\> "20") %\> \<%= submit\_tag("Name") %\> \<% end\_form\_tag %\>

you can use  
render\_text params.inspect  
in your show\_next method to see what your parameter hash is like. I am  
not sure if an action redirect can transmit parameters.
