Hello, I would like to exit an action, however, I cannot use return because it should be called from another method: def click requires_valid_login other_things end protected def requires_valid_login if !@user flash[:error] = ''you must be logged for view this page'' redirect_to :back end end Is there any elegant way to exit from action :click and don''t process "other things"? I could use: requires_valid_login or return However I don''t like this. Mage --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hope this helps... def click return unless valid_login other_things end def valid_login if !@user flash[:error] = ''you must be logged for view this page'' redirect_to :back false end true end On 8/24/06, Mage <mage-EXzRiRwUxcg@public.gmane.org> wrote:> > Hello, > > I would like to exit an action, however, I cannot use return because it > should be called from another method: > > def click > requires_valid_login > other_things > end > > protected > def requires_valid_login > if !@user > flash[:error] = ''you must be logged for view this page'' > redirect_to :back > end > end > > Is there any elegant way to exit from action :click and don''t process > "other things"? > > I could use: > requires_valid_login or return > > However I don''t like this. > > Mage > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Uhhhh to keep the syntax ruby-like you should rename valid_login to valid_login? On 8/24/06, Carl Fyffe <carl.fyffe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hope this helps... > > def click > return unless valid_login > other_things > end > > def valid_login > if !@user > flash[:error] = ''you must be logged for view this page'' > redirect_to :back > false > end > true > end > > > On 8/24/06, Mage <mage-EXzRiRwUxcg@public.gmane.org> wrote: > > > > Hello, > > > > I would like to exit an action, however, I cannot use return because it > > should be called from another method: > > > > def click > > requires_valid_login > > other_things > > end > > > > protected > > def requires_valid_login > > if !@user > > flash[:error] = ''you must be logged for view this page'' > > redirect_to :back > > end > > end > > > > Is there any elegant way to exit from action :click and don''t process > > "other things"? > > > > I could use: > > requires_valid_login or return > > > > However I don''t like this. > > > > Mage > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 8/24/06, Mage <mage-EXzRiRwUxcg@public.gmane.org> wrote:> > > Hello, > > I would like to exit an action, however, I cannot use return because it > should be called from another method: > > def click > requires_valid_login > other_things > end > > protected > def requires_valid_login > if !@user > flash[:error] = ''you must be logged for view this page'' > redirect_to :back > end > end > > Is there any elegant way to exit from action :click and don''t process > "other things"? > > I could use: > requires_valid_login or returnUse a before_filter and return false, aborting the action. jeremy --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jeremy Kemper wrote:> > > Use a before_filter and return false, aborting the action.Thank you, I am already using before filter which does the authentication, however I don''t want to abort every actions, only some of them. Is it possible to abort the action inside from a method called by the action itself? Mage --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Carl Fyffe wrote:>Hope this helps... > >def click > return unless valid_login > other_things >end > > >That''s what I am trying to avoid, the explicit return from the action itself. Mage --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mage wrote:> Jeremy Kemper wrote: > >> >> >> Use a before_filter and return false, aborting the action. > > Thank you, I am already using before filter which does the > authentication, however I don''t want to abort every actions, only some > of them.For example: before_filter :valid_login, :except => :login --Al Evans -- 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 -~----------~----~----~----~------~----~------~--~---
Al Evans wrote:> Mage wrote: >> Jeremy Kemper wrote: >> >>> >>> >>> Use a before_filter and return false, aborting the action. >> >> Thank you, I am already using before filter which does the >> authentication, however I don''t want to abort every actions, only some >> of them. > > For example: > > before_filter :valid_login, :except => :login > > --Al EvansYes before_filter accepts some options that let you skip filters on certain actions. :except is one, and :only is the other. You can give it a single action name or an array of action names. before_filter :valid_login, :only => [:protected_one, :protected_two] -- 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 -~----------~----~----~----~------~----~------~--~---