Module: AdminHelper

Defined in:
lib/generators/flexible_admin/templates/admin_helper.rb

Instance Method Summary collapse

Instance Method Details

#active_if(selected) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/generators/flexible_admin/templates/admin_helper.rb', line 23

def active_if(selected)
  if selected
    "active"
  else
    nil
  end
end

#admin_nav_item(item) ⇒ Object



19
20
21
# File 'lib/generators/flexible_admin/templates/admin_helper.rb', line 19

def admin_nav_item(item)
  (:li, link_to(item.humanize.titlecase, Rails.application.routes.url_helpers.send("admin_#{item}_path")), :class => active_if(controller_name == item))
end

#help_text_present?(all_variables) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/generators/flexible_admin/templates/admin_helper.rb', line 31

def help_text_present?(all_variables)
  all_variables.include?(:help)
end

#optional_label(form, field, label, cssclass = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/generators/flexible_admin/templates/admin_helper.rb', line 3

def optional_label(form, field, label, cssclass = nil)
  if label.present?
    if cssclass.present?
      form.label field, label, :class => cssclass
    else
      form.label field, label
    end
  else
    if cssclass.present?
      form.label field, label, :class => cssclass
    else
      form.label field
    end
  end
end

#toggle(resource, attribute) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/generators/flexible_admin/templates/admin_helper.rb', line 35

def toggle(resource, attribute)
  if resource.send(attribute)
    link_to "True", toggle_admin_path(resource, attribute)
  else
    link_to "False", toggle_admin_path(resource, attribute)
  end
end