Skip to content

Instantly share code, notes, and snippets.

@pullmonkey
Created November 16, 2011 20:55
Show Gist options
  • Save pullmonkey/1371354 to your computer and use it in GitHub Desktop.
Save pullmonkey/1371354 to your computer and use it in GitHub Desktop.
formgen sample helper
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