Created
November 16, 2011 20:55
-
-
Save pullmonkey/1371354 to your computer and use it in GitHub Desktop.
formgen sample helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FooSetupHelper | |
def setup_foo(obj) | |
obj.build_baz if obj.baz.blank? | |
obj.bars.build if obj.bars.empty? | |
return obj | |
end | |
def build_select_list(assoc, options={}) | |
name = options[:name] || "name" | |
scope = options[:scope] || "all" | |
begin | |
# name and id associations | |
assoc.to_s.classify.constantize.send(scope).map{|a| [a.send(name), a.id]} | |
rescue | |
# use id for text and value | |
assoc.to_s.classify.constantize.send(scope).map(&:id) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment