Module: TbCore::ApplicationHelper
- Defined in:
- app/helpers/tb_core/application_helper.rb
Instance Method Summary collapse
- #cache_key_for_spud_collection(collection, key: 'view', cache_params: [], for_user: false) ⇒ Object
-
#current_site_name ⇒ Object
rubocop:enable Rails/HelperInstanceVariable.
- #tb_form_error_field(record, attribute) ⇒ Object
- #tb_form_error_header(record) ⇒ Object
- #tb_form_errors(record, *fields_to_display) ⇒ Object
- #tb_form_field(attribute) ⇒ Object
- #tb_form_for(record, options = {}, &block) ⇒ Object
-
#tb_page_title ⇒ Object
rubocop:disable Rails/HelperInstanceVariable.
Instance Method Details
#cache_key_for_spud_collection(collection, key: 'view', cache_params: [], for_user: false) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/helpers/tb_core/application_helper.rb', line 76 def cache_key_for_spud_collection(collection, key:'view', cache_params:[], for_user:false) cache_keys = [controller_name, action_name, key] cache_keys << collection.collect(&:updated_at).max().try(:utc).try(:to_i) if for_user cache_keys << current_user_id end if cache_params.any? cache_keys += cache_params.collect{ |cache_param| params[cache_param] || 'nil' } end cache_keys += collection.collect(&:id) cache_key = cache_keys.join('/') if cache_key.length > 250 return Digest::SHA1.hexdigest(cache_key) else return cache_key end end |
#current_site_name ⇒ Object
rubocop:enable Rails/HelperInstanceVariable
72 73 74 |
# File 'app/helpers/tb_core/application_helper.rb', line 72 def current_site_name return TbCore.config.site_name end |
#tb_form_error_field(record, attribute) ⇒ Object
43 44 45 46 47 48 |
# File 'app/helpers/tb_core/application_helper.rb', line 43 def tb_form_error_field(record, attribute) = record.errors[attribute].first if return content_tag :p, , class: 'help-block form-field-error' end end |
#tb_form_error_header(record) ⇒ Object
36 37 38 39 40 41 |
# File 'app/helpers/tb_core/application_helper.rb', line 36 def tb_form_error_header(record) if record.errors.any? = "Please correct the following #{'error'.pluralize(record.errors.size)}:" return content_tag :h4, , class: 'form-field-error' end end |
#tb_form_errors(record, *fields_to_display) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/tb_core/application_helper.rb', line 16 def tb_form_errors(record, *fields_to_display) if record.errors.any? content_tag :div, class: 'form-errors test' do concat( tb_form_error_header(record) + content_tag(:ul) do if fields_to_display.any? = fields_to_display.collect{ |field| record.errors.(field) }.flatten() else = record.errors. end .each do |msg| concat content_tag(:li, msg) end end ) end end end |
#tb_form_field(attribute) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'app/helpers/tb_core/application_helper.rb', line 50 def tb_form_field(attribute) content_tag :div, class: 'form-group' do concat label_tag attribute, attribute, class: 'col-sm-2 control-label' concat(content_tag(:div, class: 'col-sm-10') do text_field_tag attribute, placeholder: attribute, class: 'form-control' end) end end |
#tb_form_for(record, options = {}, &block) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/tb_core/application_helper.rb', line 3 def tb_form_for(record, = {}, &block) [:builder] = TbCore::FormBuilder [:html] ||= {} if [:html][:class] [:html][:class] += ' form-horizontal' else [:html][:class] = 'form-horizontal' end return form_for(record, , &block) end |
#tb_page_title ⇒ Object
rubocop:disable Rails/HelperInstanceVariable
60 61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/tb_core/application_helper.rb', line 60 def tb_page_title if content_for?(:title) title = content_for(:title) + ' | ' + TbCore.site_name elsif @page_title title = @page_title + ' | ' + TbCore.site_name else title = TbCore.site_name end return content_tag :title, title end |