I would like to be able to easily build a <title> string. Here is how I am doing it right now (I have omitted parts not relevant): In the layout: <title><%= title %></title> Which calls: module ApplicationHelper def title @title_parts.join '' | '' end end and @title_parts is build like so: class ApplicationController < ActionController::Base before_filter :prepare_views protected def prepare_views # other stuff prepend_title t :pnc end def prepend_title item @title_parts ||= [] @title_parts.insert 0, item end end class DashboardController < ApplicationController before_filter :prepare_title def index prepend_title t :home end protected def prepare_title prepend_title t :dashboard end end How might I clean this up? My ideal would be for each controller to be able to call "title" setting its part of the title, and for individual actions to manually prepend their title part: class ApplicationController title t :pnc end class DashboardController title t :dashboard def index prepend_title :home end end Such an approach presents some problems, the first being that "t" is not available in the class scope. So I''m a bit stuck here. Thomas -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Thomas,> How might I clean this up? My ideal would be for each controller to be > able to call "title" setting its part of the title, and for individual > actions to manually prepend their title part:You may have a look to this screencast from Ryan Bates : http://railscasts.com/episodes/30-pretty-page-title Pretty clean and efficient! Hope it helps ;) @lex
Thanks, that seems to be the right idea. Here''s what I ultimately settled on...the following results in "Home | Dashboard | PNC" for a request to DashboardController#index. class ApplicationController < ActionController::Base def self.title item before_filter do |controller| controller.instance_eval do title item end end end title :pnc def initialize @title_parts = [] super end protected def title item @title_parts.insert 0, item end end module ApplicationHelper def title @title_parts.map { |part| t part }.join '' | '' end end class DashboardController < ApplicationController title :dashboard def index title :home end end <title><%= title %></title> Thomas On Apr 21, 3:38 am, Alexandre Friquet <a...-7A39yuGQHbbJDZsZoshWJA@public.gmane.org> wrote:> Hi Thomas, > > > How might I clean this up? My ideal would be for each controller to be > > able to call "title" setting its part of the title, and for individual > > actions to manually prepend their title part: > > You may have a look to this screencast from Ryan Bates :http://railscasts.com/episodes/30-pretty-page-title > > Pretty clean and efficient! > > Hope it helps ;) > > @lex > > smime.p7s > 2KViewDownload-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.