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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-11 08:26 UTC
Re: Action calling another action several times at once
On Jun 11, 8:53 am, Paul Lee <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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> 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 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---