Module: StorytimeAdmin::ApplicationHelper
- Defined in:
- app/helpers/storytime_admin/application_helper.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
|
# File 'app/helpers/storytime_admin/application_helper.rb', line 3
def method_missing method, *args, &block
if method.to_s.end_with?('_path') or method.to_s.end_with?('_url')
if main_app.respond_to?(method)
main_app.send(method, *args)
else
super
end
else
super
end
end
|
Instance Method Details
#has_many_association?(model, attribute) ⇒ Boolean
40
41
42
|
# File 'app/helpers/storytime_admin/application_helper.rb', line 40
def has_many_association?(model, attribute)
model.reflect_on_all_associations(:has_many).map(&:name).include?(attribute)
end
|
#respond_to?(method) ⇒ Boolean
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/helpers/storytime_admin/application_helper.rb', line 16
def respond_to?(method)
if method.to_s.end_with?('_path') or method.to_s.end_with?('_url')
if main_app.respond_to?(method)
true
else
super
end
else
super
end
end
|
#sortable(column, title = nil) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/helpers/storytime_admin/application_helper.rb', line 28
def sortable(column, title=nil)
title ||= column.titleize
direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
direction_arrow = if column == sort_column
direction == "asc" ? icon("caret-up") : icon("caret-down")
else
nil
end
link_to "#{title} #{direction_arrow}".html_safe, params.merge(sort: column, direction: direction, page: nil)
end
|