def test foo = redirect_to(:action => "foo").to_s and return render :text => foo + " bar" end def foo render :text => "foo " end This code prints foo while it should foo bar why? thank you --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
No, that should display "foo " in the browser after the redirected request comes in to the app. The initial request hits the test action, which redirects to action foo *and returns* which prevents render :text => foo + " bar" from ever being called. This is the correct behavior as well because you can only render or redirect once per action. On the second request (from the redirect), the browser will hit the foo action and display "foo ". -Bill slava wrote:> def test > foo = redirect_to(:action => "foo").to_s and return > render :text => foo + " bar" > end > > def foo > render :text => "foo " > end > > > This code prints > foo > while it should > foo bar > why? thank you > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
thank you for quick response. the reason i asked is because i need to call multiple actions from one controller action in sequence like def daily log += render or redirect_to or render_to_string(:controller => ''another_controller'', :action => ''someaction'') log += render or redirect_to or render_to_string(:controller => ''another_controller'', :action => ''someaction'') ... render :text => log end i am not sure how to do this. i thought ''and return'' at the and of render call would do it, but that does not work. what is the right way? On Dec 2, 10:15 pm, William Pratt <bi...-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote:> No, that should display "foo " in the browser after the redirected > request comes in to the app. The initial request hits the test action, > which redirects to action foo *and returns* which prevents render :text > => foo + " bar" from ever being called. This is the correct behavior as > well because you can only render or redirect once per action. On the > second request (from the redirect), the browser will hit the foo action > and display "foo ". > > -Bill > > slava wrote: > > def test > > foo = redirect_to(:action => "foo").to_s and return > > render :text => foo + " bar" > > end > > > def foo > > render :text => "foo " > > end > > > This code prints > > foo > > while it should > > foo bar > > why? thank you--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Dec 3, 6:25 am, slava <slava_mike...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> thank you for quick response. > the reason i asked is because i need to call multiple actions from one > controller action in sequence > like > def daily > log += render or redirect_to or render_to_string(:controller => > ''another_controller'', :action => ''someaction'') > log += render or redirect_to or render_to_string(:controller => > ''another_controller'', :action => ''someaction'')Calling render_xxx doesn''t actually execute the code for the specified action. What are you actually trying to do ? Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 5 Dec 2007, at 11:50, slava wrote:> I want to execute multiple actions in a row from one call to a > controller, collect results from each into a string for logging. I am > not sure how to make it any more clear than that. I thought my > previous description pretty much said just that. I want to execute a > call to a daily action, which performs a batch of actions and logs > results of each. >You can call other actions from the controller you''re running in (since actions are just public instance methods), calling the actions from another controllers is another subject (since you''d have to create the instance of that controller yourself and set it up appropriately). Sounds like these actions you''re calling should actually be model code, at which point it becomes easy. Fred> thank you, > Slava > > On Dec 3, 1:14 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On Dec 3, 6:25 am, slava <slava_mike...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: >> >>> thank you for quick response. >>> the reason i asked is because i need to callmultipleactions from one >>> controller action in sequence >>> like >>> def daily >>> log += render or redirect_to or render_to_string(:controller => >>> ''another_controller'', :action => ''someaction'') >>> log += render or redirect_to or render_to_string(:controller => >>> ''another_controller'', :action => ''someaction'') >> >> Calling render_xxx doesn''t actually execute the code for the >> specified >> action. What are you actually trying to do ? >> >> Fred--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thank you for the answer. Do you know how I can create instances of the other controllers? I do need to keep them as controllers (not models) as they are controllers and sometimes are called directly by clients. Basically I just need to batch a bunch of calls to multiple controllers in a row, and collecting results. thank you. Slava On Dec 5, 4:03 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 5 Dec 2007, at 11:50, slava wrote: > > > I want to execute multiple actions in a row from one call to a > > controller, collect results from each into a string for logging. I am > > not sure how to make it any more clear than that. I thought my > > previous description pretty much said just that. I want to execute a > > call to a daily action, which performs a batch of actions and logs > > results of each. > > You can call other actions from the controller you''re running in > (since actions are just public instance methods), calling the actions > from another controllers is another subject (since you''d have to > create the instance of that controller yourself and set it up > appropriately). > > Sounds like these actions you''re calling should actually be model > code, at which point it becomes easy. > > Fred > > > thank you, > > Slava > > > On Dec 3, 1:14 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On Dec 3, 6:25 am, slava <slava_mike...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > >>> thank you for quick response. > >>> the reason i asked is because i need to callmultipleactions from one > >>> controller action in sequence > >>> like > >>> def daily > >>> log += render or redirect_to or render_to_string(:controller => > >>> ''another_controller'', :action => ''someaction'') > >>> log += render or redirect_to or render_to_string(:controller => > >>> ''another_controller'', :action => ''someaction'') > > >> Calling render_xxx doesn''t actually execute the code for the > >> specified > >> action. What are you actually trying to do ? > > >> Fred--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I found the answer I was looking for :) here http://matthall.wordpress.com/2006/12/06/how-to-execute-a-rails-controller-action-via-cron/ it turn out I need to add require ''action_controller/integration'' to environment.rb then run a script with something like ./script/runner -e production "app ActionController::Integration::Session.new; app.get ''account/ send_newsletters''" On Dec 5, 2:45 pm, slava <slava_mike...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Thank you for the answer. > Do you know how I can create instances of the other controllers? I do > need to keep them as controllers (not models) as they are controllers > and sometimes are called directly by clients. Basically I just need to > batch a bunch of calls to multiple controllers in a row, and > collecting results. > > thank you. > Slava > > On Dec 5, 4:03 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On 5 Dec 2007, at 11:50, slava wrote: > > > > I want to execute multiple actions in a row from one call to a > > > controller, collect results from each into a string for logging. I am > > > not sure how to make it any more clear than that. I thought my > > > previous description pretty much said just that. I want to execute a > > > call to a daily action, which performs a batch of actions and logs > > > results of each. > > > You can call other actions from the controller you''re running in > > (since actions are just public instance methods), calling the actions > > from another controllers is another subject (since you''d have to > > create the instance of that controller yourself and set it up > > appropriately). > > > Sounds like these actions you''re calling should actually be model > > code, at which point it becomes easy. > > > Fred > > > > thank you, > > > Slava > > > > On Dec 3, 1:14 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > >> On Dec 3, 6:25 am, slava <slava_mike...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > >>> thank you for quick response. > > >>> the reason i asked is because i need to callmultipleactions from one > > >>> controller action in sequence > > >>> like > > >>> def daily > > >>> log +=renderor redirect_to or render_to_string(:controller => > > >>> ''another_controller'', :action => ''someaction'') > > >>> log +=renderor redirect_to or render_to_string(:controller => > > >>> ''another_controller'', :action => ''someaction'') > > > >> Calling render_xxx doesn''t actually execute the code for the > > >> specified > > >> action. What are you actually trying to do ? > > > >> Fred--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---