Edge Rails currently has a bug / misfeature regarding around filters which don''t yield, the intention is to support cases like this: around_filter :authorization_required def authorization_required if logged_in? yield else redirect_to authentication_url end end I personally use this idiom, but I''m interested in hearing from anyone else who does, and what issues they''ve struck with the current edge-filters. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 29, 10:43 pm, "Michael Koziarski" <mich...@koziarski.com> wrote:> Edge Rails currently has a bug / misfeature regarding around filters > which don''t yield, the intention is to support cases like this: > > around_filter :authorization_required > > def authorization_required > if logged_in? > yield > else > redirect_to authentication_url > end > endCan I ask, without sounding like a *complete* idiot, what the intent of the yield statement would be in this scenario? My understanding of around_filter is to run some code both before and after every action. There''s already a defined sequence of events going on -- so what would one be yielding *to* ? For example, in a before_filter, if I want "normal processing" to occur, I just make sure I don''t return false from my filter method. I don''t have to explicitly "yield" back to keep the ball moving. Obviously the intent here is for something more interesting - can you say a word or two about it? Thanks! Jeff (feel free to continue this on rails-talk instead, if that''s more appropriate) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On 7/3/07, Jeff <cohen.jeff@gmail.com> wrote:> > On Jun 29, 10:43 pm, "Michael Koziarski" <mich...@koziarski.com> > wrote: > > Edge Rails currently has a bug / misfeature regarding around filters > > which don''t yield, the intention is to support cases like this: > > > > around_filter :authorization_required > > > > def authorization_required > > if logged_in? > > yield > > else > > redirect_to authentication_url > > end > > end > > Can I ask, without sounding like a *complete* idiot, what the intent > of the yield statement would be in this scenario? My understanding of > around_filter is to run some code both before and after every action. > There''s already a defined sequence of events going on -- so what would > one be yielding *to* ?Around filters are like a wrapper for your action, where ''yield'' is the action. This is one of the reasons we all love ruby, and why rails would be really hard to implement in other languages. If you don''t yield it''s just like a before filter returning false. Very handy. AFAIK you should usually use around filters instead of before-filters so you can clear whatever instance variables you just set (so that they don''t have the potential of leaking between requests in production mode). I use that idiom, and I haven''t upgraded to edge rails yet. Courtenay --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
> Can I ask, without sounding like a *complete* idiot, what the intent > of the yield statement would be in this scenario? My understanding of > around_filter is to run some code both before and after every action. > There''s already a defined sequence of events going on -- so what would > one be yielding *to* ?You''re yielding to that ''defined sequence of events''. it lets you do stuff like: ActiveRecord::Base.cache do yield end (though rails does this for you now) However I''ve found that it lets you make your larger before_filter / after filters read much more nicely. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
> AFAIK you should usually use around filters instead of before-filters > so you can clear whatever instance variables you just set (so that > they don''t have the potential of leaking between requests in > production mode).Each request gets a new controller instance, so that''s not accurate. -- Cheers Koz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 3, 9:22 pm, "Michael Koziarski" <mich...@koziarski.com> wrote:> You''re yielding to that ''defined sequence of events''. it lets you do > stuff like: > > ActiveRecord::Base.cache do > yield > end > > (though rails does this for you now)Thanks a lot, Koz. (And note to self: before asking, rtfm :-) Jeff --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 3, 2007, at 7:28 PM, "Michael Koziarski" <michael@koziarski.com> wrote:> >> AFAIK you should usually use around filters instead of before-filters >> so you can clear whatever instance variables you just set (so that >> they don''t have the potential of leaking between requests in >> production mode). > > Each request gets a new controller instance, so that''s not accurate. > >Oh.. I think I meant @@class variables courtenay> > > -- > Cheers > > Koz > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---