Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Overview

Helpers found in the ApplicationHelper are present in all views on the site.

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#already_prayed_for?(prayer_id) ⇒ Boolean

Checks to see if a certain prayer request was already prayed for during the current session


27
28
29
30
31
32
# File 'app/helpers/application_helper.rb', line 27

def already_prayed_for?(prayer_id)
  # Check for the prayed_for array stored in a session and if there is none, create an empty array.
  # Then check if the prayer_id's String representation is in the array.
  # Return the boolean result of this
  (session[:prayed_for] ||= []).include? prayer_id.to_s
end

#prayed_for_number(user_prayed_for, count) ⇒ String

Generates a statement related to how many people prayed for a prayer


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/application_helper.rb', line 42

def prayed_for_number(user_prayed_for, count)
  # Has the user already prayed for this prayer request?
  if user_prayed_for
    # Was the user the only person who prayed for it?
    if count == 1
      "You prayed for this."
    # More than one person prayed for it
    else
      "You and #{pluralize count-1, "other person"} prayed for this."
    end
  # The user has nor prayed for this prayer request
  else
    # Does this prayer request have any prayers?
    if count == 0
      "Be the first to pray for this."
    # One or more people prayed for it
    else
      "#{pluralize count, "other person"} prayed for this."
    end
  end
end

#timeago(time, options = {}) ⇒ String

Creates HTML5 time tag for use by the jquery.timeago plugin


13
14
15
16
17
18
19
# File 'app/helpers/application_helper.rb', line 13

def timeago(time, options = {})
  # Assign HTML id as "timeago" if no other id is given
  options[:id] ||= "timeago"
  
  # Return HTML5 time tag
  (:time, time.to_s, options.merge(:datetime => time.getutc.iso8601)) if time
end