I have a special case(does not normally occur) render in a filter. Because its in a filter, I can''t end execution with a ''return'' which would work otherwise. Therefore I get this error: Can only render or redirect once per action My code in gist: class MyController < ApplicationController before_filter :authenticate def priviledged_action redirect_to :action => "vip_room" end protected def authenticate if params[:password] != "pass" render :status => 403, :text => "Access denied" # Things I have tried to end execution here: # ''return'' does end execution as simply returns filter # ''exit'' causes crash # I can''t think of a way to use catch/throw end end end Can anyone please advise? -- 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 Apr 8, 7:59 pm, Zac Zheng <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have a special case(does not normally occur) render in a filter. > Because its in a filter, I can''t end execution with a ''return'' which > would work otherwise. Therefore I get this error: > > Can only render or redirect once per action >what version of rails are you using ? In rails 2 and above rendering from a filter should cause the filter chain to halt. in previous versions you had to return false from your filter. Fred> My code in gist: > > class MyController < ApplicationController > before_filter :authenticate > > def priviledged_action > redirect_to :action => "vip_room" > end > > protected > def authenticate > if params[:password] != "pass" > render :status => 403, :text => "Access denied" > # Things I have tried to end execution here: > # ''return'' does end execution as simply returns filter > # ''exit'' causes crash > # I can''t think of a way to use catch/throw > end > end > end > > Can anyone please advise? > -- > 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> what version of rails are you using ? In rails 2 and above rendering > from a filter should cause the filter chain to halt. in previous > versions you had to return false from your filter.You''re right! My semi pseudocode oversimplified my actual code. There''s a logic that prevents false being returned from the filter. Thanks mate -- 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 -~----------~----~----~----~------~----~------~--~---