lib/jquery/gridify/grid.rb
def build_columns(klass, only, except, presets, include, actions)
      #debugger
      # stringify
      only = Array(only).map { |s| s.to_s }
      except = Array(except).map { |s| s.to_s }
      presets ||= []

      if presets.length > 0
        hashed_defs = {}

        klass.columns.collect do |ar|
          #debugger
          next if only.present? && !only.include?(ar.name)
          next if except.present? && except.include?(ar.name)
          hashed_defs[ar.name] = strct2args(klass, ar)
        end.compact

        if include
          include.each do |sub_model|
            my_model = sub_model.to_s
            if klass.inheritable_attributes[:reflections][sub_model].options[:class_name]
              my_class = klass.inheritable_attributes[:reflections][sub_model].options[:class_name].to_s
              model = klass.inheritable_attributes[:reflections][sub_model].options[:class_name].to_s
            else
              my_class = my_model
            end
            Object.const_get(my_class.capitalize).columns.collect do |ar|
              #debugger
              next if only.present? && !only.include?("#{my_model}.#{ar.name}")
              next if except.present? && except.include?("#{my_model}.#{ar.name}")
              hashed_defs["#{my_model}.#{ar.name}"] = strct2args(klass, ar)
            end
          end
        end

        if actions
          hashed_defs["row_actions"] = actions_args()
        end

        # Take sequence from colModel
        self.colModel = []
        presets.each do |col|
          # create column with default args merged with options given for this column
          self.colModel << GridColumn.new(hashed_defs[col[:name]].merge(col))
        end
      else
        # Take sequence from database definition
        self.colModel = klass.columns.collect do |ar|
          #debugger
          next if only.present? && !only.include?(ar.name)
          next if except.present? && except.include?(ar.name)
          args = strct2args(klass, ar)
          # create column with default args merged with options given for this column
          GridColumn.new(args)
        end.compact

        if include
          include.each do |sub_model|
            my_model = sub_model.to_s
            if klass.inheritable_attributes[:reflections][sub_model].options[:class_name]
              my_class = klass.inheritable_attributes[:reflections][sub_model].options[:class_name].to_s
              model = klass.inheritable_attributes[:reflections][sub_model].options[:class_name].to_s
            else
              my_class = my_model
            end
            Object.const_get(my_class.capitalize).columns.collect do |ar|
              #debugger
              next if only.present? && !only.include?("#{my_model}.#{ar.name}")
              next if except.present? && except.include?("#{my_model}.#{ar.name}")
              args = strct2args(klass, ar, "#{my_model}.")
              # create column with default args merged with options given for this column
              self.colModel << GridColumn.new(args)
            end
          end
        end
      end
    end
def build_columns(klass, only, except, presets, include, actions)
      #debugger
      # stringify
      only = Array(only).map { |s| s.to_s }
      except = Array(except).map { |s| s.to_s }
      presets ||= []

      if presets.length > 0
        hashed_defs = {}

        klass.columns.collect do |ar|
          #debugger
          next if only.present? && !only.include?(ar.name)
          next if except.present? && except.include?(ar.name)
          hashed_defs[ar.name] = strct2args(klass, ar)
        end.compact

        if include
          include.each do |sub_model|
            my_model = sub_model.to_s
            if klass.inheritable_attributes[:reflections][sub_model].options[:class_name]
              my_class = klass.inheritable_attributes[:reflections][sub_model].options[:class_name].to_s
              model = klass.inheritable_attributes[:reflections][sub_model].options[:class_name].to_s
            else
              my_class = my_model
            end
            Object.const_get(my_class.capitalize).columns.collect do |ar|
              #debugger
              next if only.present? && !only.include?("#{my_model}.#{ar.name}")
              next if except.present? && except.include?("#{my_model}.#{ar.name}")
              hashed_defs["#{my_model}.#{ar.name}"] = strct2args(klass, ar)
            end
          end
        end

        if actions
          hashed_defs["row_actions"] = actions_args()
        end

        # Take sequence from colModel
        self.colModel = []
        presets.each do |col|
          # create column with default args merged with options given for this column
          self.colModel << GridColumn.new(hashed_defs[col[:name]].merge(col))
        end
      else
        # Take sequence from database definition
        self.colModel = klass.columns.collect do |ar|
          #debugger
          next if only.present? && !only.include?(ar.name)
          next if except.present? && except.include?(ar.name)
          args = strct2args(klass, ar)
          # create column with default args merged with options given for this column
          GridColumn.new(args)
        end.compact

        if include
          include.each do |sub_model|
            my_model = sub_model.to_s
            if klass.inheritable_attributes[:reflections][sub_model].options[:class_name]
              my_class = klass.inheritable_attributes[:reflections][sub_model].options[:class_name].to_s
              model = klass.inheritable_attributes[:reflections][sub_model].options[:class_name].to_s
            else
              my_class = my_model
            end
            Object.const_get(my_class.capitalize).columns.collect do |ar|
              #debugger
              next if only.present? && !only.include?("#{my_model}.#{ar.name}")
              next if except.present? && except.include?("#{my_model}.#{ar.name}")
              args = strct2args(klass, ar, "#{my_model}.")
              # create column with default args merged with options given for this column
              self.colModel << GridColumn.new(args)
            end
          end
        end
      end
    end
# isnt there something in rails to do this already?
 def parse_options( keys, options )
   ops = keys.inject({}) do |h, k|
     val = options.delete(k)
     h[k] = val unless val.nil?
     h
   end
   ops || {}
 end
 generate list of columns based on AR model
 option:  :only or :except
          :col_options  hash of hash of preset values for columns (eg from cookie) { :title => {:width => 98}}