[#4182] Hooked up nested attributes for Deliverable -> LaborExpense
This commit is contained in:
@@ -6,6 +6,8 @@ class DeliverablesController < InheritedResources::Base
|
||||
before_filter :find_contract
|
||||
before_filter :authorize
|
||||
|
||||
helper :contracts
|
||||
|
||||
def index
|
||||
redirect_to contract_url(@project, @contract)
|
||||
end
|
||||
@@ -21,7 +23,6 @@ class DeliverablesController < InheritedResources::Base
|
||||
def update
|
||||
@deliverable = begin_of_association_chain.deliverables.find_by_id(params[:id])
|
||||
params[:deliverable] = params[:fixed_deliverable] || params[:hourly_deliverable]
|
||||
@deliverable.attributes = params[:deliverable]
|
||||
update! { contract_url(@project, @contract) }
|
||||
end
|
||||
|
||||
|
||||
@@ -1,2 +1,7 @@
|
||||
module ContractsHelper
|
||||
def setup_nested_deliverable_records(deliverable)
|
||||
returning(deliverable) do |d|
|
||||
d.labor_expenses.build if d.labor_expenses.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,6 +5,8 @@ class Deliverable < ActiveRecord::Base
|
||||
belongs_to :contract
|
||||
belongs_to :manager, :class_name => 'User', :foreign_key => 'manager_id'
|
||||
has_many :labor_expenses
|
||||
|
||||
accepts_nested_attributes_for :labor_expenses
|
||||
|
||||
# Validations
|
||||
validates_presence_of :title
|
||||
|
||||
@@ -5,9 +5,6 @@ class LaborExpense < ActiveRecord::Base
|
||||
belongs_to :deliverable
|
||||
|
||||
# Validations
|
||||
validates_presence_of :hours
|
||||
validates_presence_of :budget
|
||||
validates_presence_of :deliverable
|
||||
|
||||
# Accessors
|
||||
|
||||
|
||||
@@ -22,7 +22,18 @@
|
||||
<% end %>
|
||||
|
||||
<%= form.input :total, :input_html => {:size => 10}, :wrapper_html => {:class => 'deliverable_total_input'} %>
|
||||
|
||||
<% form.inputs :name => l(:text_deliverable_finances) do %>
|
||||
<% form.semantic_fields_for :labor_expenses do |labor_expense| %>
|
||||
<% labor_expense.inputs :name => l(:field_labor) do %>
|
||||
<%= labor_expense.input :hours, :label => l(:text_short_hours), :input_html => {:size => 10} %>
|
||||
<%= labor_expense.input :budget, :label => l(:text_dollar_sign), :input_html => {:size => 10} %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
|
||||
<% form.buttons do %>
|
||||
<%= form.commit_button :label => l(:button_save) %>
|
||||
<%= link_to(l(:button_cancel), cancel_path) %>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<%= content_tag(:h2, h(resource.title)) %>
|
||||
|
||||
<% semantic_form_for [@project, @contract, resource], :url => contract_deliverable_path(@project, @contract, resource), :html => {:class => 'deliverable tabular'} do |form| %>
|
||||
<% semantic_form_for [@project, @contract, setup_nested_deliverable_records(resource)], :url => contract_deliverable_path(@project, @contract, resource), :html => {:class => 'deliverable tabular'} do |form| %>
|
||||
<%= render :partial => 'form', :object => form, :locals => {:cancel_path => contract_path(@project, @contract)} %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<%= content_tag(:h2, l(:text_new_deliverable)) %>
|
||||
|
||||
<% semantic_form_for [@project, @contract, resource], :url => contract_deliverables_path(@project, @contract), :html => {:class => 'deliverable tabular'} do |form| %>
|
||||
<% semantic_form_for [@project, @contract, setup_nested_deliverable_records(resource)], :url => contract_deliverables_path(@project, @contract), :html => {:class => 'deliverable tabular'} do |form| %>
|
||||
<%= render :partial => 'form', :object => form, :locals => {:cancel_path => contract_path(@project, @contract)} %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user