Skip to content
Browse files

better code organization, thanks sobrinho

Signed-off-by: Joel Nimety <jnimety@continuity.net>
  • Loading branch information...
1 parent e7d3e0f commit dbc7452d62425d471310f3781b992e772484e24d @jnimety jnimety committed Oct 20, 2011
Showing with 12 additions and 7 deletions.
  1. +12 −7 lib/formtastic/inputs/check_boxes_input.rb
View
19 lib/formtastic/inputs/check_boxes_input.rb
@@ -152,13 +152,7 @@ def disabled?(value)
end
def selected_values
- @selected_values_cache ||= if object.respond_to?(method)
- selected_items = [object.send(method)].compact.flatten
-
- [*selected_items.map { |o| send_or_call_or_object(value_method, o) }].compact
- else
- []
- end
+ @selected_values ||= make_selected_values
end
def disabled_values
@@ -175,6 +169,17 @@ def input_name
"#{object_name}[#{association_primary_key || method}][]"
end
+ protected
+
+ def make_selected_values
+ if object.respond_to?(method)
+ selected_items = [object.send(method)].compact.flatten
+
+ [*selected_items.map { |o| send_or_call_or_object(value_method, o) }].compact
+ else
+ []
+ end
+ end
end
end
end

0 comments on commit dbc7452

Please sign in to comment.
Something went wrong with that request. Please try again.