我的問題是,當我試圖在名爲「clients」的控制器中處理更新操作時(我正在請求HTML並且未處理JSON),我得到的406不可接受,我的預感是我在我的嵌套if語句的結構中缺少一些東西,因爲這隻發生在下面列出的嵌套進程之一的驗證失敗時。我已經通過我的代碼,並試圖重構幾種方式,但似乎無法繞過這一個。希望一組新的眼睛可能會看到我沒有看到的東西。RoR返回406不可接受,請求HTML
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? && [email protected]_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? && [email protected]_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? && [email protected]_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" && [email protected]_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
我重新編寫了可讀性代碼。請注意,正如@ksol所說,末尾有兩個「末尾」與任何內容都不相符。我假設他們是複製/粘貼剩餘物。 – numbers1311407
你可以發佈你的堆棧跟蹤 – jamesc