Module: FancyTable::ViewHelpers

Defined in:
lib/fancy_table/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#fancy_table(objects, options = {}) ⇒ Object



28
29
30
31
# File 'lib/fancy_table/view_helpers.rb', line 28

def fancy_table(objects, options = {})
  options.merge! objects: objects
  render partial: 'fancy_table/fancy_table', locals: options
end


15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fancy_table/view_helpers.rb', line 15

def link_to_object(object, label_attribute = nil)
  if object.class.respond_to? :table_name
    pathmethod = "#{object.class.table_name.singularize}_path"
    if respond_to? pathmethod
      link_to object.send( label_attribute || object.class.default_order_column ), send(pathmethod, object)
    else
      object.to_s
    end
  else
    object.to_s
  end
end

#wrap_if(condition, symbol, *args, &block) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/fancy_table/view_helpers.rb', line 3

def wrap_if(condition, symbol, *args, &block)
  if condition
    send symbol, *args, &block
  else
    capture(&block)
  end
end

#wrap_unless(condition, symbol, *args, &block) ⇒ Object



11
12
13
# File 'lib/fancy_table/view_helpers.rb', line 11

def wrap_unless(condition, symbol, *args, &block)
  wrap_if(!condition, symbol, *args, &block)
end