lib/data_tables.rb in data_tables-0.1.0 vs lib/data_tables.rb in data_tables-0.1.1

- old
+ new

@@ -1,6 +1,5 @@ -require 'data_tables/data_tables_helper' module DataTablesController def self.included(cls) cls.extend(ClassMethods) end @@ -158,11 +157,13 @@ columns = [] options[:columns].each do |column| if column.kind_of? Symbol # a column from the database, we don't need to do anything columns << {:name => column, :attribute => column} elsif column.kind_of? Hash - columns << {:name => column[:name], :special => column} + col_hash = { :name => column[:name], :special => column } + col_hash[:attribute] = column[:attribute] if column[:attribute] + columns << col_hash end end columns end @@ -185,22 +186,22 @@ end end # gets the value for a column and row def datatables_instance_get_value(instance, column) - if column[:attribute] - val = instance.send(column[:attribute].to_sym) - return I18n.t(val.to_s.to_sym, :default => val.to_s) if not val.blank? - return '' - elsif column[:special] + if column[:special] special = column[:special] if special[:method] return method(special[:method].to_sym).call(instance) elsif special[:eval] proc = lambda { obj = instance; binding } return Kernel.eval(special[:eval], proc.call) end + elsif column[:attribute] + val = instance.send(column[:attribute].to_sym) + return I18n.t(val.to_s.to_sym, :default => val.to_s) if not val.blank? + return '' end return "value not found" end def datatable_source(name)