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).
> Joe R. MUDCRAP-CE wrote:
Joe
--
Posted via http://www.ruby-forum.com/.
[email protected]>
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.
undefined – the show method does ‘@item = Item.find(params[:id])’
I can think of at least three approaches that would work.
You could put an additional Item.find in the "when ‘show’ " block in
your
filter.
You could use :except on your filter and do the title assignment for
the
‘show’ method inside the method .
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?