Module: HierarchicalPageTitles::ControllerHelpers::ClassMethods

Defined in:
lib/hierarchical_page_titles/controller_helpers.rb

Instance Method Summary collapse

Instance Method Details

#window_title!(*args, &block) ⇒ Object Also known as: add_to_window_title, window_title

Public: Append a string to the list of window titles for a group of actions.

*titles - An Array of Strings which will be appended to the window

titles.

options - A Hash of options which filters the actions for which window

titles are set:
:only   - Whitelist of actions (Symbol or Array of Symbols)
:except - Blacklist of actions (Symbol or Array of Symbols)

block - A block which will be evaluated but when the action is run

and should return the value you want to add to the window
titles. Useful if this value cannot be determined right away.

Example:

class ApplicationController
  window_title 'The best site evar'
end
class FoosController < ApplicationController
  window_title!(:only => :index) { winning? ? 'Zombies' : 'Vampires' }
  def winning?
    action_name == 'index'
  end
end

# foos/index.html.erb
<%= window_title %>
<%# => 'The best site evar - Zombies' %>

# foos/new.html.erb
<%= window_title %>
<%# => 'The best site evar - Vampires' %>

Returns nothing.



44
45
46
47
48
49
50
51
52
53
# File 'lib/hierarchical_page_titles/controller_helpers.rb', line 44

def window_title!(*args, &block)
  options, titles = args.extract_options!, args
  before_filter(options) do |c|
    if block
      c.window_titles! c.instance_eval(&block)
    else
      c.window_title!(titles)
    end
  end
end