Module: Guts::ApplicationHelper
- Defined in:
- app/helpers/guts/application_helper.rb
Overview
Common helpers for the whole application
Instance Method Summary collapse
-
#controller_css_id ⇒ String
Simply creates an ID to use in the ‘body` of the layout which is a combination of the current controller and action.
-
#current_site_form_field(f) ⇒ String
Helper for settings the current site ID for a model in the form.
-
#link_to_destroy(title, object, link_opts = {}) ⇒ String
Creates a wrapper around ‘link_to` to destroy objects through javascript by creating a hidden form.
-
#menu_active?(key, strict = true) ⇒ Boolean
Determines if a menu is active in the admin panel.
-
#sub_title_for(object) ⇒ String
Creates a human-readable version of an object.
Instance Method Details
#controller_css_id ⇒ String
Simply creates an ID to use in the ‘body` of the layout which is a combination of the current controller and action
30 31 32 |
# File 'app/helpers/guts/application_helper.rb', line 30 def controller_css_id "#{params[:controller].tr('/', '_')}_#{params[:action]}" end |
#current_site_form_field(f) ⇒ String
Helper for settings the current site ID for a model in the form
52 53 54 |
# File 'app/helpers/guts/application_helper.rb', line 52 def current_site_form_field(f) f.hidden_field :site_id, value: @current_site.try(:id) end |
#link_to_destroy(title, object, link_opts = {}) ⇒ String
Creates a wrapper around ‘link_to` to destroy objects through javascript by creating a hidden form
10 11 12 13 14 15 16 |
# File 'app/helpers/guts/application_helper.rb', line 10 def link_to_destroy(title, object, link_opts = {}) html = [] html << link_to(title, '#', link_opts.merge(class: "destroy_resource #{link_opts[:class]}")) html << form_for(object, url: object, method: :delete, html: { style: 'display: none' }) {} html.join('').html_safe end |
#menu_active?(key, strict = true) ⇒ Boolean
Determines if a menu is active in the admin panel
41 42 43 44 45 46 47 |
# File 'app/helpers/guts/application_helper.rb', line 41 def (key, strict = true) if strict controller.controller_name == key.to_s else controller.controller_name.include? key.to_s end end |
#sub_title_for(object) ⇒ String
Creates a human-readable version of an object
21 22 23 |
# File 'app/helpers/guts/application_helper.rb', line 21 def sub_title_for(object) object.class.to_s.demodulize.underscore.titleize end |