Module: BaseHelper
- Defined in:
- app/helpers/base_helper.rb
Instance Method Summary collapse
- #base_path(model) ⇒ Object
- #boolean_image(boolean) ⇒ Object
- #edit_url_for(model, namespace: nil) ⇒ Object
- #price(value) ⇒ Object
- #remote_request(type, path, params = {}, target_tag_id = nil) ⇒ Object
- #short_date(date) ⇒ Object
- #translate_attribute(model, attribute = nil) ⇒ Object (also: #ta)
Instance Method Details
#base_path(model) ⇒ Object
17 18 19 |
# File 'app/helpers/base_helper.rb', line 17 def base_path(model) "/#{model.model_name.name.underscore.pluralize}" end |
#boolean_image(boolean) ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/helpers/base_helper.rb', line 34 def boolean_image(boolean) if boolean "<span class='glyphicon glyphicon-ok green'>".html_safe else "<span class='glyphicon glyphicon-remove red'>".html_safe end end |
#edit_url_for(model, namespace: nil) ⇒ Object
9 10 11 12 13 14 15 |
# File 'app/helpers/base_helper.rb', line 9 def edit_url_for(model, namespace: nil) if model.id _namespace_ = namespace ? namespace.concat('_') : namespace path = "edit_#{_namespace_}#{model.model_name.to_s.underscore}_path" Rails.application.routes.url_helpers.send(path.to_sym, id: model.id) end end |
#price(value) ⇒ Object
47 48 49 |
# File 'app/helpers/base_helper.rb', line 47 def price(value) number_to_currency(value) end |
#remote_request(type, path, params = {}, target_tag_id = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/base_helper.rb', line 21 def remote_request(type, path, params={}, target_tag_id = nil) if target_tag_id "$.#{type}('#{path}', { #{collect_request_params(params)} }, function(data) {$('##{target_tag_id}').html(data);} );" else "$.#{type}('#{path}', { #{collect_request_params(params)} } );" end end |
#short_date(date) ⇒ Object
42 43 44 45 |
# File 'app/helpers/base_helper.rb', line 42 def short_date(date) return "" unless date l(date, format: :short) end |
#translate_attribute(model, attribute = nil) ⇒ Object Also known as: ta
2 3 4 5 |
# File 'app/helpers/base_helper.rb', line 2 def translate_attribute(model, attribute = nil) return model.human_attribute_name(attribute) if attribute model.model_name.human end |