From 6357fd83e4704cd9b4e6924dffe20445235c8096 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 10 Aug 2011 15:11:45 -0700 Subject: [PATCH] [#6441] Refactor: extract method --- app/helpers/contracts_helper.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/helpers/contracts_helper.rb b/app/helpers/contracts_helper.rb index 643e451..bf6b8d4 100644 --- a/app/helpers/contracts_helper.rb +++ b/app/helpers/contracts_helper.rb @@ -30,14 +30,7 @@ module ContractsHelper # skip else options = contract.deliverables.collect do |deliverable| - option_attributes = {} - option_attributes[:value] = h(deliverable.id) - option_attributes[:selected] = "selected" if selected_key.to_i == deliverable.id - option_attributes[:disabled] = "disabled" if (deliverable.locked? || contract.locked?) && selected_key.to_i != deliverable.id - - next if deliverable.closed? && option_attributes[:selected].blank? # Skip unselected, closed - - content_tag(:option, h(deliverable.title), option_attributes) + deliverable_option(deliverable, contract, selected_key) end html << content_tag(:optgroup, options.join("\n"), :label => h(contract.name)) @@ -46,6 +39,17 @@ module ContractsHelper end.join('\n') end + def deliverable_option(deliverable, contract, selected_key) + option_attributes = {} + option_attributes[:value] = h(deliverable.id) + option_attributes[:selected] = "selected" if selected_key.to_i == deliverable.id + option_attributes[:disabled] = "disabled" if (deliverable.locked? || contract.locked?) && selected_key.to_i != deliverable.id + + return "" if deliverable.closed? && option_attributes[:selected].blank? # Skip unselected, closed + + content_tag(:option, h(deliverable.title), option_attributes) + end + def deliverable_options_for_contract(contract) contract.deliverables.collect {|d| [d.title, d.id]} end