Sha256: fbc233f1301c2f5c60637e1dc826362fc291d8a6522f7823c093a620a6f06a8f

Contents?: true

Size: 609 Bytes

Versions: 1

Compression:

Stored size: 609 Bytes

Contents

module Carnival::ModelHelper

  def to_s
    self.name
  end

  def self.included mod
    mod.extend ClassMethods
  end

  module ClassMethods
    def list_for_select(params = {})
      select = []
      select << ['', ''] if params[:add_empty_option]
      if params[:reverse]
        select.concat all.collect{|c|[c.to_s, c.id]}
      else
        select.concat all.collect{|c|[c.id, c.to_s]}
      end
      select
    end

     def to_label_options
      label = column_names.select { |column| column.eql?("name")}
      label.empty? ?  column_names.fetch(1).to_sym : label.first.to_sym
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
carnival-0.0.44 app/models/carnival/model_helper.rb