module ApplicationHelper

Public Instance Methods

block_to_partial(partial_name, options = {}, &block) click to toggle source

Only need this helper once, it will provide an interface to convert a block into a partial.

  1. Capture is a Rails helper which will ‘capture’ the output of a block into a variable

  2. Merge the ‘body’ variable into our options hash

  3. Render the partial with the given options hash. Just like calling the partial directly.

# File app/helpers/application_helper.rb, line 38
def block_to_partial(partial_name, options = {}, &block)
  options.merge!(:body => capture(&block))
  render(:partial => partial_name, :locals => options)
end
div(text) click to toggle source

Wrap text in div tags, unless text is blank

# File app/helpers/application_helper.rb, line 3
def div(text)
  "<div>#{text}</div>" unless text.blank?
end
page_title() click to toggle source

RacingAssociation.current.short_name: page title

# File app/helpers/application_helper.rb, line 8
def page_title
  return "#{RacingAssociation.current.short_name}: #{@page_title}" if @page_title
  
  if @page && !@page.title.blank?
    return "#{RacingAssociation.current.short_name}: #{@page.title}"
  end
  
  "#{RacingAssociation.current.short_name}: #{controller.controller_name.titleize}: #{controller.action_name.titleize}"
end
to_excel(value) click to toggle source

Add #to_excel to strip out CSV-invalid characters

# File app/helpers/application_helper.rb, line 26
def to_excel(value)
  if value.try :respond_to?, :gsub
    value.gsub(%r[\t\n\r]/, " ")
  else
    value
  end
end
truncate_from_end(text) click to toggle source

Defaults to text length of 20

# File app/helpers/application_helper.rb, line 19
def truncate_from_end(text)
  return text if text.blank? || text.size <= 20
  
  "...#{text[-20, 20]}"
end