2015-12-04 85 views
2

您好同事,我一直在訂購訂單管理系統。我終於弄清楚了所有的錯誤,除了一個我不能離開。一旦我刪除了客戶或訂單,我收到一條錯誤消息,說「路由錯誤」。用軌道銷燬紅寶石客戶/訂單

路由錯誤的路由匹配[POST] 「/客戶/ 2」

Rails.root:/用戶/塞西爾/桌面/ order_management_systeem

應用程序跟蹤|框架跟蹤|全跟蹤路由

這是我的路線

  Prefix Verb URI Pattern          Controller#Action 
    customer_orders GET /customers/:customer_id/orders(.:format)   orders#index 
        POST /customers/:customer_id/orders(.:format)   orders#create 
new_customer_order GET /customers/:customer_id/orders/new(.:format)  orders#new 
edit_customer_order GET /customers/:customer_id/orders/:id/edit(.:format) orders#edit 
    customer_order GET /customers/:customer_id/orders/:id(.:format)  orders#show 
        PATCH /customers/:customer_id/orders/:id(.:format)  orders#update 
        PUT /customers/:customer_id/orders/:id(.:format)  orders#update 
        DELETE /customers/:customer_id/orders/:id(.:format)  orders#destroy 
      customers GET /customers(.:format)        customers#index 
        POST /customers(.:format)        customers#create 
     new_customer GET /customers/new(.:format)       customers#new 
     edit_customer GET /customers/:id/edit(.:format)      customers#edit 
      customer GET /customers/:id(.:format)       customers#show 
        PATCH /customers/:id(.:format)       customers#update 
        PUT /customers/:id(.:format)       customers#update 
        DELETE /customers/:id(.:format)       customers#destroy 
        GET /:controller/:action/:id/:customer_id(.:format) :controller#:action 

這是我的ERB代碼

<%= link_to("Delete", customer_path(@customer), method: :delete, confirm: "Are you sure?", :class => 'action delete') %> 

銷燬控制器

def destroy 
    customer = Customer.find(params[:id]).destroy 
    flash[:notice] = "Subject '#{customer.first_name}' destroyed successfully" 
    redirect_to(:action => 'index') 
    end 
+1

請更新控制器的動作('destroy') –

+0

@AndreyDeineko謝謝你的提示 –

+0

我的意思是從所謂的控制動作的代碼的問題'破壞':) –

回答

2

行動摧毀應該沿着東西以下行:

def destroy 
    @customer = Customer.find(params[:id] 
    @customer.destroy 
    redirect_to(
    customers_path, 
    notice: 'Customer successfully deleted' 
) 
end 

而且編輯鏈接:

<%= link_to("Delete", @customer, method: :delete, data: { confirm: "Are you sure?" }) %> 

你的情況的問題,是你定義的變量customer,但在你的url_helper(customer_path(@customer))使用@customer

的另一件事情(更重要的),是你實際分配customer值,它是從數據庫刪除對象的結果:

customer = Customer.find(params[:id]).destroy 

從來沒有這樣做。

要麼

Customer.find(params[:id]).destroy 

@customer = Customer.find(params[:id]) 
@customer.destroy 
+0

謝謝你的寶貴意見,它似乎仍然沒有工作。當我檢查鏈接上的元素時,我得到了這個(Delete)也許是一個愚蠢的問題,但它是否與bootstrap有關? –

+0

你試過重寫這個動作嗎? –

+0

是的,我得到了同樣的結果。 –