From 1149d6018ef9df73be563a4bfcaac47dbb5f34af Mon Sep 17 00:00:00 2001 From: Bradly Feeley Date: Sat, 25 May 2013 12:39:07 -0700 Subject: [PATCH] Add support for when the condition of an association is a proc. --- lib/simple_form/form_builder.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb index 7680c6e5..e6b561f6 100644 --- a/lib/simple_form/form_builder.rb +++ b/lib/simple_form/form_builder.rb @@ -182,7 +182,9 @@ module SimpleForm options[:as] ||= :select options[:collection] ||= options.fetch(:collection) { - reflection.klass.where(reflection.options[:conditions]).order(reflection.options[:order]).to_a + conditions = reflection.options[:conditions] + conditions = conditions.call if conditions.is_a?(Proc) + reflection.klass.where(conditions).order(reflection.options[:order]).to_a } attribute = case reflection.macro