Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "activerecord" unless defined?(ActiveRecord)
- module ActiveRecord
- class Base
- class << self
- def collect_for_select(*args)
- options = args.extract_options!
- options = options.delete_if { |k,v| k == :as }
- if collection = find((args.first.is_a?(Array) ? args.first : :all), options)
- return collection.collect do |c|
- if c.respond_to?(options[:as])
- [c.send(options[:as]), c.id]
- elsif c.respond_to?(:name)
- [c.name, c.id]
- else
- [c.id, c.id]
- end
- end # of collect
- else
- return [[]]
- end # of if collection...
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment