Guest User

Untitled

a guest
Jul 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. require "activerecord" unless defined?(ActiveRecord)
  2.  
  3. module ActiveRecord
  4. class Base
  5. class << self
  6. def collect_for_select(*args)
  7. options = args.extract_options!
  8. options = options.delete_if { |k,v| k == :as }
  9.  
  10. if collection = find((args.first.is_a?(Array) ? args.first : :all), options)
  11. return collection.collect do |c|
  12. if c.respond_to?(options[:as])
  13. [c.send(options[:as]), c.id]
  14. elsif c.respond_to?(:name)
  15. [c.name, c.id]
  16. else
  17. [c.id, c.id]
  18. end
  19. end # of collect
  20. else
  21. return [[]]
  22. end # of if collection...
  23. end
  24. end
  25. end
  26. end
Add Comment
Please, Sign In to add comment