I would like to be able to easily build a string. Here is how
I am doing it right now (I have omitted parts not relevant):
In the layout:
<%= 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