私の問題は、「clients」という名前のコントローラーで更新アクションを処理しようとすると、406 が受け入れられないことです (HTML を要求していて、JSON を処理していません)。これは、以下にリストされているネストされたプロセスのいずれかで検証が失敗した場合にのみ発生するためです。私はコードを調べて、いくつかの方法でリファクタリングを試みましたが、これを回避できないようです。新鮮な目が私が見ていないものを見ることを願っています.
def update
@client = Client.find(params[:id])
respond_to do |format|
if params[:save_contact]
format.html { redirect_to "/clients/#{@client.id}/edit#tabs-3", :notice => 'Contact Saved!' }
format.mobile { render :action => "edit", :notice => 'Contact Saved' }
format.json { head :ok }
else
end
if params[:save_job]
format.html { redirect_to "/clients/#{@client.id}/edit#tabs-6", :notice => 'Job Saved!' }
format.mobile { render :action => "edit", :notice => 'Job Saved' }
format.json { head :ok }
else
end
if @client.update_attributes(params[:client])
@client.update_attribute(:branch_number, @client.branch.number)
if @client.wcrequested? && !@client.wcrequest_sent?
@client.update_attribute(:wcstatus, "Pending")
@client.update_attribute(:wcrequest_sent, "TRUE")
@client.update_attribute(:wcresponse_sent, "FALSE")
@client.update_attribute(:wcresponded, "FALSE")
ClientsMailer.wcreq_recieved_corp(@client, current_user).deliver
ClientsMailer.wcreq_recieved_branch(@client, current_user).deliver
else
format.html { render :action => "edit" }
format.mobile { render :action => "edit" }
format.json { render :json => @client.errors, :status => :unprocessable_entity }
end
if @client.wcstatus == "Denied"
@client.update_attribute(:wcrequest_sent, "FALSE")
@client.update_attribute(:wcrequested, "FALSE")
ClientsMailer.wcreq_completed_corp(@client, current_user).deliver
ClientsMailer.wcreq_completed_branch(@client, current_user).deliver
else
end
if @client.wcresponded? && !@client.wcresponse_sent?
@client.update_attribute(:wcresponse_sent, "TRUE")
ClientsMailer.wcreq_completed_corp(@client, current_user).deliver
ClientsMailer.wcreq_completed_branch(@client, current_user).deliver
else
end
if params[:gpreq]
@client.update_attribute(:gpstatus, "Pending GP Approval")
ClientsMailer.gpreq_recieved_corp(@client, current_user).deliver
ClientsMailer.gpreq_recieved_branch(@client, current_user).deliver
else
end
if params[:gpreply]
@client.update_attribute(:gpstatus, "GP Approval Completed")
ClientsMailer.gpreq_completed_corp(@client, current_user).deliver
ClientsMailer.gpreq_completed_branch(@client, current_user).deliver
else
end
if @client.cred_requested? && !@client.cred_req_sent?
@client.update_attribute(:cred_req_sent, "TRUE")
ClientsMailer.credreq_recieved_corp(@client, current_user).deliver
ClientsMailer.credreq_recieved_branch(@client, current_user).deliver
else
end
if @client.cred_status == "Completed" && !@client.cred_rep_sent?
@client.update_attribute(:cred_rep_sent, "TRUE")
ClientsMailer.credreq_completed_corp(@client, current_user).deliver
ClientsMailer.credreq_completed_branch(@client, current_user).deliver
else
end
format.html { redirect_to edit_client_path(@client), :notice => 'Client was successfully updated!' }
format.mobile { render :action => "edit", :notice => 'Client was successfully updated!' }
format.json { head :ok }
format.xml { render :action => "edit"}
else
format.html { render :action => "edit" }
format.mobile { render :action => "edit" }
format.json { render :json => @client.errors, :status => :unprocessable_entity }
format.xml { render :action => "edit"}
end
end
end