Sha256: 735a6b3e2993a07943c3cbc1f9ebba5b0dfea7caef1c3424d643bcdce065f172

Contents?: true

Size: 611 Bytes

Versions: 9

Compression:

Stored size: 611 Bytes

Contents

module Carnival::ModelHelper

  def to_label
    self.respond_to? :name ? self.name : self.to_s
  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_label, c.id]}
      else
        select.concat all.collect{|c|[c.id, c.to_label]}
      end
      select
    end

    def list_for_checkbox
      list = []
      all.each {|object| list << [object.id, object.to_label] }
      list
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
carnival-0.0.55 app/models/carnival/model_helper.rb
carnival-0.0.54 app/models/carnival/model_helper.rb
carnival-0.0.53 app/models/carnival/model_helper.rb
carnival-0.0.52 app/models/carnival/model_helper.rb
carnival-0.0.51 app/models/carnival/model_helper.rb
carnival-0.0.50 app/models/carnival/model_helper.rb
carnival-0.0.49 app/models/carnival/model_helper.rb
carnival-0.0.48 app/models/carnival/model_helper.rb
carnival-0.0.47 app/models/carnival/model_helper.rb