# Action calling another action several times at once

**URL:** <https://www.ruby-forum.com/t/action-calling-another-action-several-times-at-once/140140>\
**Category:** Rails\
**Created:** [June 11, 2008, 9:53am UTC](https://www.ruby-forum.com/t/action-calling-another-action-several-times-at-once/140140 "2008-06-11T09:53:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [June 11, 2008, 9:53am UTC](https://www.ruby-forum.com/t/action-calling-another-action-several-times-at-once/140140/1 "2008-06-11T09:53:33Z")

</div>

Hi.

I’m a newbie on rails.

There’re two actions in a controller.

def show\_many\_verses  
…  
end

def show\_one\_verse  
…  
end

And as you can guess from those action names…  
I wanna call ‘show\_one\_verse’ several times in ‘show\_many\_verse’ action.

The following is what I tried and got failed.

def show\_many\_verses  
1.upto(10) { |v|  
redirect\_to :action =\> ‘show\_one\_verse’, :params =\> { :verse\_seq =\>  
v }  
}  
end

And that code occured an error saying in an action ‘redirect\_to’ can be  
called at most once.

How should I change my code?

Thanks in advance.

- Paul

---

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [June 11, 2008, 10:28am UTC](https://www.ruby-forum.com/t/action-calling-another-action-several-times-at-once/140140/2 "2008-06-11T10:28:01Z")

</div>

On Jun 11, 8:53 am, Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> def show\_one\_verse  
> redirect\_to :action =\> ‘show\_one\_verse’, :params =\> { :verse\_seq =\>  
> v }  
> }

redirect\_to means ‘send the browser a response that says go to url X’,  
so redirecting more than once is meaningless.  
It sounds like you just want to render a partial with the appropriate  
collection, ie if @verses is the array of verses to display then stick  
\<%= render :partial =\> ‘verse’, :collection =\> @verses%\> in your view  
and rails will render \_verse.html.erb once for each element of the  
array (and in that file there will be a local variable verse  
containing the current element.

Fred

---

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [June 11, 2008, 11:10am UTC](https://www.ruby-forum.com/t/action-calling-another-action-several-times-at-once/140140/3 "2008-06-11T11:10:27Z")

</div>

Hi, Fred.

Thanks a lot for your comment.

I followed what you suggested and it’s working perfectly.

I’d been struggling with this problem for 2 days

and now it’s solved… 🙂

Thanks !

- Paul

> redirect\_to means ‘send the browser a response that says go to url X’,  
> so redirecting more than once is meaningless.  
> It sounds like you just want to render a partial with the appropriate  
> collection, ie if @verses is the array of verses to display then stick  
> \<%= render :partial =\> ‘verse’, :collection =\> @verses%\> in your view  
> and rails will render \_verse.html.erb once for each element of the  
> array (and in that file there will be a local variable verse  
> containing the current element.
> 
> Fred
