Hi all I''m still having my troubles with DoubleRenderError in Rails. Some time ago I learnt that I should always return after redirecting to avoid this problem: return redirect_to :action => ''list'' First question: do I have to return when using the render(...) method, too? Now I''m still having a problem because I''m getting a DoubleRenderError. The trace looks like the following: - I open the link http://my-app.xx/member - The default action index is launched in member_controller: def index show render(:action => ''show'') and return end - The show action looks like this: if false # Just for testing purposes, should do some user authorization # Everything''s OK, render the show.rhtml template like intended else # Display an error message and pretend that the site does not exist return render(:file => "#{RAILS_ROOT}/public/404.html", :layout => false, :status => 404) end I guess it''s clear why I''m getting the error message (after the rendered 404.html file I get back into the index action and try to render the action ''show'', too), but I don''t know how to avoid it in a clean way? Or should I just redirect to action ''show'' instead of calling it manually? Any help is greatly appreciated. :-) Thanks, Josh -- 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 -~----------~----~----~----~------~----~------~--~---
The simple way to put it is this. You can only call render or redirect_to once per action, period. Neither one of these methods stop execution of an action either. So, you don''t have to use return with render or with redirect_to as long another call to either of them is encountered in the path of execution. If you are running into the problem this frequently, it probably means you need to rethink how you are designing your actions. -Bill Joshua Muheim wrote:> Hi all > > I''m still having my troubles with DoubleRenderError in Rails. Some time > ago I learnt that I should always return after redirecting to avoid this > problem: > > return redirect_to :action => ''list'' > > First question: do I have to return when using the render(...) method, > too? > > Now I''m still having a problem because I''m getting a DoubleRenderError. > The trace looks like the following: > > - I open the link http://my-app.xx/member > - The default action index is launched in member_controller: > def index > show > render(:action => ''show'') and return > end > - The show action looks like this: > if false # Just for testing purposes, should do some user > authorization > # Everything''s OK, render the show.rhtml template like intended > else > # Display an error message and pretend that the site does not exist > return render(:file => "#{RAILS_ROOT}/public/404.html", :layout => > false, :status => 404) > end > > I guess it''s clear why I''m getting the error message (after the rendered > 404.html file I get back into the index action and try to render the > action ''show'', too), but I don''t know how to avoid it in a clean way? > > Or should I just redirect to action ''show'' instead of calling it > manually? > > Any help is greatly appreciated. :-) Thanks, Josh >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The first thing I notice is that you are rendering show twice: def index show render(:action => ''show'') and return end should just be def index show end Joshua Muheim wrote:> Hi all > > I''m still having my troubles with DoubleRenderError in Rails. Some time > ago I learnt that I should always return after redirecting to avoid this > problem: > > return redirect_to :action => ''list'' > > First question: do I have to return when using the render(...) method, > too? > > Now I''m still having a problem because I''m getting a DoubleRenderError. > The trace looks like the following: > > - I open the link http://my-app.xx/member > - The default action index is launched in member_controller: > def index > show > render(:action => ''show'') and return > end > - The show action looks like this: > if false # Just for testing purposes, should do some user > authorization > # Everything''s OK, render the show.rhtml template like intended > else > # Display an error message and pretend that the site does not exist > return render(:file => "#{RAILS_ROOT}/public/404.html", :layout => > false, :status => 404) > end > > I guess it''s clear why I''m getting the error message (after the rendered > 404.html file I get back into the index action and try to render the > action ''show'', too), but I don''t know how to avoid it in a clean way? > > Or should I just redirect to action ''show'' instead of calling it > manually? > > Any help is greatly appreciated. :-) Thanks, Josh >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 both. So I guess I''ll have to rename my show.rhtml to index.rhtml... Would have been nice to not having to, but that''s OK. :-) -- 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 -~----------~----~----~----~------~----~------~--~---
On 7 Nov 2007, at 02:33, William Pratt wrote:> > The first thing I notice is that you are rendering show twice: > > def index > show > render(:action => ''show'') and return > end > > should just be > > def index > show > endThat''s not quite true. Just calling show doesn''t make you render the show template (unless the show method itself calls render :action => ''show'') This should do the job def show if some_authorisation_condition ... (don''t call render or redirect return true else render(:file => "#{RAILS_ROOT}/public/404.html", :layout =>false, :status => 404) return false end end def index if show render :action => ''show'' end end Fred> > > > > > > Joshua Muheim wrote: >> Hi all >> >> I''m still having my troubles with DoubleRenderError in Rails. Some >> time >> ago I learnt that I should always return after redirecting to avoid >> this >> problem: >> >> return redirect_to :action => ''list'' >> >> First question: do I have to return when using the render(...) >> method, >> too? >> >> Now I''m still having a problem because I''m getting a >> DoubleRenderError. >> The trace looks like the following: >> >> - I open the link http://my-app.xx/member >> - The default action index is launched in member_controller: >> def index >> show >> render(:action => ''show'') and return >> end >> - The show action looks like this: >> if false # Just for testing purposes, should do some user >> authorization >> # Everything''s OK, render the show.rhtml template like intended >> else >> # Display an error message and pretend that the site does not >> exist >> return render(:file => "#{RAILS_ROOT}/public/404.html", :layout => >> false, :status => 404) >> end >> >> I guess it''s clear why I''m getting the error message (after the >> rendered >> 404.html file I get back into the index action and try to render the >> action ''show'', too), but I don''t know how to avoid it in a clean way? >> >> Or should I just redirect to action ''show'' instead of calling it >> manually? >> >> Any help is greatly appreciated. :-) Thanks, Josh >> > > -- > Sincerely, > > William Pratt > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thats true, but he does have a render in there, and thats why I said that. On second thought, a redirect_to might be better and always render from show so that show can be called on it''s own as well. -Bill Frederick Cheung wrote:> On 7 Nov 2007, at 02:33, William Pratt wrote: > > >> The first thing I notice is that you are rendering show twice: >> >> def index >> show >> render(:action => ''show'') and return >> end >> >> should just be >> >> def index >> show >> end >> > > That''s not quite true. Just calling show doesn''t make you render the > show template (unless the show method itself calls render :action => > ''show'') > > This should do the job > > def show > if some_authorisation_condition > ... (don''t call render or redirect > return true > else > render(:file => "#{RAILS_ROOT}/public/404.html", :layout > =>false, :status => 404) > return false > end > end > > def index > if show > render :action => ''show'' > end > end > > Fred > > >> >> >> >> >> Joshua Muheim wrote: >> >>> Hi all >>> >>> I''m still having my troubles with DoubleRenderError in Rails. Some >>> time >>> ago I learnt that I should always return after redirecting to avoid >>> this >>> problem: >>> >>> return redirect_to :action => ''list'' >>> >>> First question: do I have to return when using the render(...) >>> method, >>> too? >>> >>> Now I''m still having a problem because I''m getting a >>> DoubleRenderError. >>> The trace looks like the following: >>> >>> - I open the link http://my-app.xx/member >>> - The default action index is launched in member_controller: >>> def index >>> show >>> render(:action => ''show'') and return >>> end >>> - The show action looks like this: >>> if false # Just for testing purposes, should do some user >>> authorization >>> # Everything''s OK, render the show.rhtml template like intended >>> else >>> # Display an error message and pretend that the site does not >>> exist >>> return render(:file => "#{RAILS_ROOT}/public/404.html", :layout => >>> false, :status => 404) >>> end >>> >>> I guess it''s clear why I''m getting the error message (after the >>> rendered >>> 404.html file I get back into the index action and try to render the >>> action ''show'', too), but I don''t know how to avoid it in a clean way? >>> >>> Or should I just redirect to action ''show'' instead of calling it >>> manually? >>> >>> Any help is greatly appreciated. :-) Thanks, Josh >>> >>> >> -- >> Sincerely, >> >> William Pratt >> >> >> > > > > >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---