Module: Workbench::ListHelper
- Defined in:
- app/helpers/workbench/list_helper.rb
Overview
Helpers that generate simple lists, tables etc.
Instance Method Summary collapse
- #list_tag(object, method) ⇒ Object
- #recent_objects_list(model, recent_objects) ⇒ Object
- #similarly_named_records_list(instance) ⇒ Object
Instance Method Details
#list_tag(object, method) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/helpers/workbench/list_helper.rb', line 31 def list_tag(object, method) return content_tag(:div, object_tag(object) + "has no method #{method}") unless object.respond_to?(method) if object.send(method).any? content_tag(:ul) do object.send(method).collect{|i| content_tag(:li, object_tag(i)) }.join.html_safe end else content_tag(:span, "No #{method} attached.", class: :warning) end end |
#recent_objects_list(model, recent_objects) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/workbench/list_helper.rb', line 18 def recent_objects_list(model, recent_objects) partial = nil base = model.name.tableize if self.respond_to?("#{base}_recent_objects_partial") partial = "/#{base}/recent_objects_list" else partial = '/shared/data/project/recent_objects_list' end render partial: partial , locals: {recent_objects: recent_objects} end |
#similarly_named_records_list(instance) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/helpers/workbench/list_helper.rb', line 4 def similarly_named_records_list(instance) model = instance.class name = instance.name records = model.where(['(name LIKE ? OR NAME like ?) AND id != ?', "#{name}%", "%#{name}%", instance]).limit(5) content_tag(:span) do content_tag(:em, 'Similarly named records: ') + content_tag(:span) do (records.count == 0 ? 'none' : records.collect { |r| link_to(r.name, r) }.join(', ').html_safe) end end end |