我的问题是,在尝试处理名为“clients”的控制器中的更新操作时,我得到了一个不可接受的 406(我正在请求 HTML 而不是在处理 JSON)我的直觉是我的嵌套结构中缺少一些东西if 语句,因为这只发生在下面列出的嵌套进程之一的验证失败时。我已经浏览了我的代码并尝试了几种重构方法,但似乎无法绕过这个方法。希望一双新的眼睛能看到我看不到的东西。
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