Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Overview

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

Author:

  • Robert Klubenspies

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

Parameters:

  • prayer_id (Integer)

    the id of the Prayer object we'll be checking

Returns:

  • (Boolean)

    whether or not the prayer_id was found in this session (true would indicate that it was found and that this Prayer was already prayed for)

See Also:

Since:

  • 0.1.2



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

Parameters:

  • user_prayed_for (Boolean)

    wether or not the user looking at the prayer request already prayed for it

  • count (Integer)

    a count of how many time the prayer request has been prayed for

Returns:

  • (String)

    a statement related to how many people prayed for a prayer

See Also:

Author:

  • Robert Klubenspies

Since:

  • 0.1.2



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

Parameters:

  • time

    the timestamp of the entry we're generating a time tag for

  • options (Array) (defaults to: {})

    HTML options for the tag

Returns:

  • (String)

    an HTML5 time tag

See Also:

Since:

  • 0.1.0



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