I think the problem here is that your page title value is going to need to be evaluated as one of the first items in your view... so you can't really define the page title in your view. Controller seems to be the easiest place to define this to make sure you can set the page title value before it gets called. How and where you do this is is the question.

I think a lot of how you organize this is going to depend on what you want your titles to be. Are they always going to be one-off titles, or can they be derived programatically (possibly based on some values stored in your database). If they can be arrived at programmatically every time, you can extract everything into a view helper and not touch your controller code.

On Feb 23, 2007, at 12:49 PM, Patrick Crowley wrote:

I think it does belong in the view, actually.

Your solution isn't bad (though I'd make it a helper instead), but I'm thinking about something more automagic.

While I haven't figured out a technical solution for this yet, I like the implict DRYness of setting the title once, in the view, and not worrying about it again.

I guess title-izing the current action name could work, but that'd get a bit gnarly with super long page titles.

-- Patrick


On Feb 23, 2007, at 12:29 pm, Nathan Colgate Clark wrote:

I agree, this does clutter up your controller... but since page titles are usually action-specific I can't think of a better place for them. You wouldn't want to try and rig something like this in the model... and passing it off into the view (i.e. scrubbing it out of an <h1>) doesn't feel right other. Maybe a before_filter? it would get it out of your individual action methods and down at the bottom of the controller. Something like...

before_filter :load_page_title

private

def load_page_title
   @page_title=
       case controller.action_name
           when "news"
               "News"
           when "show"
               @object.name
        end
   end
     Just throwing stuff out there....

-Nathan
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

Reply via email to