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
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
the before_filter is launched BEFORE calling the action (as stated by the name of the filter)
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@andreas-s.net <mailto:rails-mailing-list@andreas-s.net>>:
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@siebert-wd.de>
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
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
I too tend towards 3. It’s neater.
Vish