Module: Blogit::ApplicationHelper

Defined in:
app/helpers/blogit/application_helper.rb

Constant Summary

TIMETAG_FORMAT =
"%Y-%m-%dT%TZ"

Instance Method Summary (collapse)

Instance Method Details

- (Object) actions(content_or_options = {}, options = {}, &block)

A helper method for creating a <div> tag with class ‘actions’ Used for option links and form buttons



22
23
24
# File 'app/helpers/blogit/application_helper.rb', line 22

def actions(content_or_options={}, options ={}, &block)
  div_with_default_class(:actions, content_or_options, options, &block)
end

- (Object) errors_on(object, attribute)

Returns the first error message for an ActiveRecord model instance

Parameters:

  • object

    A model instance to check

  • attribute

    A symbol or string for attribute name to check for errors



10
11
12
# File 'app/helpers/blogit/application_helper.rb', line 10

def errors_on(object, attribute)
  object.errors[attribute].first.to_s
end

- (Object) field(content_or_options = {}, options = {}, &block)

A helper method for creating a <div> tag with class ‘field’ Used for separating form fields



16
17
18
# File 'app/helpers/blogit/application_helper.rb', line 16

def field(content_or_options={}, options ={}, &block)
  div_with_default_class(:field, content_or_options, options, &block)
end

- (Object) login_required(content_or_options = {}, options = {}, &block)

A helper method for creating a <div> tag with class ‘login_required’ Will only render content if there is a logged in user



28
29
30
# File 'app/helpers/blogit/application_helper.rb', line 28

def (content_or_options={}, options ={}, &block)
  div_with_default_class(:login_required, content_or_options, options, &block) if current_blogger
end

- (Object) time_tag(time_object, format = nil, options = {})

Returns an HTML 5 time tag

Parameters:

  • time_object

    Any Time or DateTime object

  • format (String, Symbol) (defaults to: nil)

    If passed a string will treat as a strftime format. If passed a symbol will treat as pre-set datetime format.



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/helpers/blogit/application_helper.rb', line 36

def time_tag(time_object, format = nil, options ={})
  # if there's a specified format and it's a string, assume it's an strftime string
  if format && format.is_a?(String)
    time_string = time_object.strftime(format)
  # if there's a specified format and it's a symbol, assume it's a predefined format
  elsif format && format.is_a?(Symbol)
    time_string = time_object.to_s(format)
  else
    time_string = time_object.to_s
  end
  options.merge(datetime: time_object.strftime(TIMETAG_FORMAT))
  (:time, time_string, options)
end