Module: Comable::Admin::ApplicationHelper
- Defined in:
- app/helpers/comable/admin/application_helper.rb
Instance Method Summary collapse
- #build_fields(f, type) ⇒ Object
- #button_to_add_fields(name, f, type, options = {}) ⇒ Object
- #button_to_remove_fields(name, options = {}) ⇒ Object
- #enable_advanced_search? ⇒ Boolean
- #gravatar_tag(email, options = {}) ⇒ Object
- #link_to_add_fields(name, f, association, options = {}) ⇒ Object
- #link_to_save ⇒ Object
- #page_name ⇒ Object
Instance Method Details
#build_fields(f, type) ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/helpers/comable/admin/application_helper.rb', line 30 def build_fields(f, type) new_object = f.object.send("build_#{type}") f.send("#{type}_fields", new_object, child_index: "new_#{type}") do |builder| render("comable/admin/shared/#{type}_fields", f: builder) end end |
#button_to_add_fields(name, f, type, options = {}) ⇒ Object
25 26 27 28 |
# File 'app/helpers/comable/admin/application_helper.rb', line 25 def (name, f, type, = {}) new_fields = build_fields(f, type) content_tag(:button, name, .merge(class: "ransack add_fields #{[:class]}", 'data-field-type' => type, 'data-content' => "#{new_fields}")) end |
#button_to_remove_fields(name, options = {}) ⇒ Object
21 22 23 |
# File 'app/helpers/comable/admin/application_helper.rb', line 21 def (name, = {}) content_tag(:button, name, .merge(class: "ransack remove_fields #{[:class]}")) end |
#enable_advanced_search? ⇒ Boolean
38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/comable/admin/application_helper.rb', line 38 def enable_advanced_search? grouping_params = params[:q][:g] conditions_params = grouping_params.values.first[:c] value_params = conditions_params.values.first[:v] value_params.values.first[:value].present? rescue NoMethodError false end |
#gravatar_tag(email, options = {}) ⇒ Object
8 9 10 11 |
# File 'app/helpers/comable/admin/application_helper.rb', line 8 def gravatar_tag(email, = {}) hash = Digest::MD5.hexdigest(email) image_tag "//www.gravatar.com/avatar/#{hash}?default=mm", end |
#link_to_add_fields(name, f, association, options = {}) ⇒ Object
13 14 15 16 17 18 19 |
# File 'app/helpers/comable/admin/application_helper.rb', line 13 def link_to_add_fields(name, f, association, = {}) new_object = f.object.class.reflect_on_association(association).klass.new fields = f.fields_for(association, new_object, child_index: "new_#{association}") do |builder| render("comable/admin/shared/#{association.to_s.singularize}_fields", ff: builder) end link_to(name, 'javascript:void(0)', .merge(onclick: "add_fields(this, '#{association}', '#{escape_javascript(fields)}')")) end |
#link_to_save ⇒ Object
4 5 6 |
# File 'app/helpers/comable/admin/application_helper.rb', line 4 def link_to_save link_to Comable.t('admin.actions.save'), 'javascript:$("form").submit()', class: 'btn btn-primary' end |
#page_name ⇒ Object
48 49 50 |
# File 'app/helpers/comable/admin/application_helper.rb', line 48 def page_name [controller_name, action_name].join(':') end |