Module ApplicationHelper
In: app/helpers/application_helper.rb

Methods

Public Instance methods

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.

[Source]

    # File app/helpers/application_helper.rb, line 38
38:   def block_to_partial(partial_name, options = {}, &block)
39:     options.merge!(:body => capture(&block))
40:     concat(render(:partial => partial_name, :locals => options))
41:   end

Wrap text in div tags, unless text is blank

[Source]

   # File app/helpers/application_helper.rb, line 3
3:   def div(text)
4:     "<div>#{text}</div>" unless text.blank?
5:   end

RacingAssociation.current.short_name: page title

[Source]

    # File app/helpers/application_helper.rb, line 8
 8:   def page_title
 9:     return "#{RacingAssociation.current.short_name}: #{@page_title}" if @page_title
10:     
11:     if @page && !@page.title.blank?
12:       return "#{RacingAssociation.current.short_name}: #{@page.title}"
13:     end
14:     
15:     "#{RacingAssociation.current.short_name}: #{controller.controller_name.titleize}: #{controller.action_name.titleize}"
16:   end

Add to_excel to strip out CSV-invalid characters

[Source]

    # File app/helpers/application_helper.rb, line 26
26:   def to_excel(value)
27:     if value.try :respond_to?, :gsub
28:       value.gsub(/[\t\n\r]/, " ")
29:     else
30:       value
31:     end
32:   end

Defaults to text length of 20

[Source]

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

[Validate]