I have: before_filter :set_page_title def set_page_title @page_title = case action_name when ''new'' then ''Submit Item'' when ''list'' then ''Items'' when ''show'' then "Item - #{@item.title}" end end Is there any way to get the ''show'' line to work? @item isn''t defined when the before filter runs, and an after filter happens after ''show'' is apparently completely rendered (so @page_title doesn''t appear). Thanks, Joe -- 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 -~----------~----~----~----~------~----~------~--~---
Hi Joe, Joe Ruby MUDCRAP-CE wrote:> when ''show'' then "Item - #{@item.title}" > > @item isn''t defined when the before filter runsIsn''t defined? Or isn''t ''knowable''? Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> Hi Joe, > > Joe Ruby MUDCRAP-CE wrote: >> when ''show'' then "Item - #{@item.title}" >> >> @item isn''t defined when the before filter runs > > Isn''t defined? Or isn''t ''knowable''? > > Billundefined -- the show method does ''@item = Item.find(params[:id])'' Joe -- 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 -~----------~----~----~----~------~----~------~--~---
the before_filter is launched BEFORE calling the action (as stated by the name of the filter) 2006/10/4, Joe Ruby MUDCRAP-CE <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > > Bill Walton wrote: > > Hi Joe, > > > > Joe Ruby MUDCRAP-CE wrote: > >> when ''show'' then "Item - #{@item.title}" > >> > >> @item isn''t defined when the before filter runs > > > > Isn''t defined? Or isn''t ''knowable''? > > > > Bill > > undefined -- the show method does ''@item = Item.find(params[:id])'' > > Joe > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Michael Siebert <info-norLuBQQNv0t+8dGM1inlw@public.gmane.org> www.siebert-wd.de - Gedanken lesen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Siebert wrote:> the before_filter is launched BEFORE calling the action (as stated by > the name of the filter) > > 2006/10/4, Joe Ruby MUDCRAP-CE <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org > <mailto:rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>>: > > > Bill Walton wrote: > > Hi Joe, > > > > Joe Ruby MUDCRAP-CE wrote: > >> when ''show'' then "Item - #{@item.title}" > >> > >> @item isn''t defined when the before filter runs > > > > Isn''t defined? Or isn''t ''knowable''? > > > > Bill > > undefined -- the show method does ''@item = Item.find(params[:id])'' > > Joe > > -- > Posted via http://www.ruby-forum.com/. > > info-norLuBQQNv0t+8dGM1inlw@public.gmane.org> > > www.siebert-wd.de <http://www.siebert-wd.de> - Gedanken lesen > >Why not add another filter that instantiates @item for show (and also the other actions that need it, such as edit, update), and then call it will prepend_before_filter (thus ensuring it gets run before your other before_filter. HTH CT --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Joe, Joe Ruby MUDCRAP-CE>> >> Joe Ruby MUDCRAP-CE wrote: >>> when ''show'' then "Item - #{@item.title}" >>> >>> @item isn''t defined when the before filter runs >> >> Isn''t defined? Or isn''t ''knowable''? > > undefined -- the show method does ''@item = Item.find(params[:id])''I can think of at least three approaches that would work. 1) You could put an additional Item.find in the "when ''show'' " block in your filter. 2) You could use :except on your filter and do the title assignment for the ''show'' method inside the method . 3) You could drop the before_filter altogether and do the title assignments inside each method. My guess is that you''re probably doing this in the first place in an effort to be DRY; putting all the page title assignment code in one place. Good instinct. Not one to be followed without thought, though. Personally, in this situation, I''d tend toward number 3. Can you tell me why? Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I too tend towards 3. It''s neater. Vish On 10/4/06, Bill Walton <bill.walton-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:> > > Hi Joe, > > Joe Ruby MUDCRAP-CE > >> > >> Joe Ruby MUDCRAP-CE wrote: > >>> when ''show'' then "Item - #{@item.title}" > >>> > >>> @item isn''t defined when the before filter runs > >> > >> Isn''t defined? Or isn''t ''knowable''? > > > > undefined -- the show method does ''@item = Item.find(params[:id])'' > > I can think of at least three approaches that would work. > > 1) You could put an additional Item.find in the "when ''show'' " block in > your > filter. > 2) You could use :except on your filter and do the title assignment for > the > ''show'' method inside the method . > 3) You could drop the before_filter altogether and do the title > assignments > inside each method. > > My guess is that you''re probably doing this in the first place in an > effort > to be DRY; putting all the page title assignment code in one place. Good > instinct. Not one to be followed without thought, though. > > Personally, in this situation, I''d tend toward number 3. Can you tell me > why? > > Best regards, > Bill > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---