@ -35,17 +35,23 @@ class HourlyRatesController < ApplicationController
existing_attributes = params [ :user ] [ :existing_rate_attributes ]
unless existing_attributes . nil?
# this selects all rate_ids for the current user and the current project
rate_ids = HourlyRate . count ( :conditions = > { :user_id = > @user , :project_id = > @project } ,
:group = > :id ,
:select = > [ :id ] ) . to_hash
existing_attributes = existing_attributes . reject { | a | rate_ids . has_key? a . id }
end
else
new_attributes = nil
existing_attributes = { }
end
if request . post?
@user . new_rate_attributes = new_attributes if new_attributes
@user . existing_rate_attributes = existing_attributes
end
if request . post? && @user . save
flash [ :notice ] = l ( :notice_successful_update )
redirect_back_or_default ( :action = > 'show' , :id = > @user , :project_id = > @project )