Module: RailsDiffTime::Helpers

Defined in:
lib/rails/diff/time/helpers.rb

Overview

Helper methods for displaying time differences in a human-readable format.

Instance Method Summary collapse

Instance Method Details

#diff_time(certain_time, element_name = "span", attributes = {}, auto_update: false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rails/diff/time/helpers.rb', line 6

def diff_time(certain_time, element_name = "span", attributes = {}, auto_update: false)
  return "" if certain_time.nil?

  result = render "rails-diff-time/diff_time", locals: {
    diff_time: diff_time_str(certain_time),
    element_name: element_name,
    attributes: attributes,
    certain_time: certain_time,
    auto_update: auto_update
  }

  # If auto_update is enabled and the script has not been included yet
  if auto_update && !@_diff_time_script_included
    @_diff_time_script_included = true
    result += diff_time_script_tag
  end

  result
end