Action calling another action several times at once

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

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 } }

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

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.. :slight_smile:

Thanks !

- Paul