Module: BaseHelper

Defined in:
app/helpers/base_helper.rb

Instance Method Summary collapse

Instance Method Details

#boolean_image(boolean) ⇒ Object



37
38
39
40
41
42
43
# File 'app/helpers/base_helper.rb', line 37

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

#decorate(object, decorator) {|decorator.new(object)| ... } ⇒ Object

Yields:

  • (decorator.new(object))


54
55
56
# File 'app/helpers/base_helper.rb', line 54

def decorate(object, decorator)
  yield decorator.new(object)
end

#edit_admin_url_for(model) ⇒ Object



17
18
19
20
21
22
# File 'app/helpers/base_helper.rb', line 17

def edit_admin_url_for(model)
  if model.id
    path = "edit_admin_#{model.model_name.to_s.underscore}_path"
    Rails.application.routes.url_helpers.send(path.to_sym, id: model.id)
  end
end

#edit_url_for(model) ⇒ Object



10
11
12
13
14
15
# File 'app/helpers/base_helper.rb', line 10

def edit_url_for(model)
  if model.id
    path = "edit_#{model.model_name.to_s.underscore}_path"
    Rails.application.routes.url_helpers.send(path.to_sym, id: model.id)
  end
end

#price(value) ⇒ Object



50
51
52
# File 'app/helpers/base_helper.rb', line 50

def price(value)
  number_to_currency(value)
end

#remote_request(type, path, params = {}, target_tag_id = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/base_helper.rb', line 24

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



45
46
47
48
# File 'app/helpers/base_helper.rb', line 45

def short_date(date)
  return "" unless date
  l(date, format: :short)
end

#translate_attribute(model, attribute = nil) ⇒ Object Also known as: ta



3
4
5
6
# File 'app/helpers/base_helper.rb', line 3

def translate_attribute(model, attribute = nil)
  return model.human_attribute_name(attribute) if attribute
  model.model_name.human
end