[#4420] Refactor: extract duplicated data to query.
This commit is contained in:
1 parent
1120b39ed6
commit
4b162f85bf
3 files changed
+13
-2
No files matched your search
@@ -14,7 +14,7 @@ class DeliverablesController < InheritedResources::Base
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
@deliverable = begin_of_association_chain.deliverables.build(params[:deliverable])
|
@deliverable = begin_of_association_chain.deliverables.build(params[:deliverable])
|
||||||
if params[:deliverable] && params[:deliverable][:type] && ['FixedDeliverable','HourlyDeliverable','RetainerDeliverable'].include?(params[:deliverable][:type])
|
if params[:deliverable] && params[:deliverable][:type] && Deliverable.valid_types.include?(params[:deliverable][:type])
|
||||||
@deliverable.type = params[:deliverable][:type]
|
@deliverable.type = params[:deliverable][:type]
|
||||||
end
|
end
|
||||||
create! { contract_url(@project, @contract) }
|
create! { contract_url(@project, @contract) }
|
||||||
|
|||||||
@@ -72,6 +72,17 @@ class Deliverable < ActiveRecord::Base
|
|||||||
type == "RetainerDeliverable"
|
type == "RetainerDeliverable"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.valid_types
|
||||||
|
['FixedDeliverable','HourlyDeliverable','RetainerDeliverable']
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.valid_types_to_select
|
||||||
|
valid_types.inject([]) do |types, type|
|
||||||
|
types << [type.gsub(/Deliverable/i,''), type]
|
||||||
|
types
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if Rails.env.test?
|
if Rails.env.test?
|
||||||
generator_for :title, :method => :next_title
|
generator_for :title, :method => :next_title
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<% if resource.new_record? %>
|
<% if resource.new_record? %>
|
||||||
<li class="select required" id="deliverable_type_input">
|
<li class="select required" id="deliverable_type_input">
|
||||||
<%= form.label(:type, l(:field_type)) %>
|
<%= form.label(:type, l(:field_type)) %>
|
||||||
<%= form.select(:type, [["Fixed", "FixedDeliverable"], ["Hourly", "HourlyDeliverable"], ["Retainer", "RetainerDeliverable"]], {:include_blank => false}, {:class => 'type'}) %>
|
<%= form.select(:type, Deliverable.valid_types_to_select, {:include_blank => false}, {:class => 'type'}) %>
|
||||||
|
|
||||||
<%= form.select(:frequency, RetainerDeliverable.frequencies_to_select, :include_blank => false) %>
|
<%= form.select(:frequency, RetainerDeliverable.frequencies_to_select, :include_blank => false) %>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
Reference in new issue
Block a user