2016-07-12 1 views
0

내가보기에는 할 수없는 이상한 라우팅 오류로 보입니다. 나는 Rails 4.2.6을 사용하고 고객을위한 비계를 생성하고있다. 나는 고객의 목록을 볼 수 있어요하지만 고객을 편집 할 때 나는 모든 꽤 많이 나는이 내 경로를 변경 않았지만 비계가 만든 것입니다라우팅 오류 업데이트/생성 레코드

No route matches [POST] "/customers/49"

오류를 얻을 :

resources :customers do 
    resources :comments, only: [:new, :create, :edit, :update] 
    end 

하지만 기본 스 캐 폴딩으로 시도해 보았는데 동일한 오류가 발생합니다.

는 고객을위한 경로입니다

   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 

"편집"페이지 생성 된 HTML이 게시물 요청

<form class="edit_customer" id="edit_customer_49" action="/customers/49" accept-charset="UTF-8" method="post"> 

하고 "새로운"페이지

에 대해 동일 보여줍니다
<form class="new_customer" id="new_customer" action="/customers" accept-charset="UTF-8" method="post"> 

대부분 모든 것이 스캐 폴딩의 생산물이므로 내가 왜 그는 잘못했다. 생성 된 HTML이 POST를 사용하는 이유는 무엇이며 어떻게 작동합니까?

레일스 초보자를 도와 주셔서 감사합니다.

UPDATE 이 좋아, 내 모델에서 내가이가 내 편집/새로운 형태

CUSTOMER_TYPE = ["A", "B"] 

있습니다

<%= f.label :customer_type %> 
    <%= f.select :customer_type, Customer::CUSTOMER_TYPE, {include_blank: true}, {index: nil} %> 

나는 내 양식 중 위의 라인을 가지고가는 경우에, 편집 및 새 양식 모두 오류없이 작동합니다.

+0

POST 양식이지만이 방법은 패치로 제공되어야합니다. 생성 된 HTML은''와 같은 라인을 가지고 있습니까? – GoGoCarl

+0

예 @GoGoCarl, 알겠습니다. ' – mack

+0

맥이 알아 냈어? – bkunzi01

답변

0

귀하의 경로 목록에 '업데이트'에 대한 PATCH 또는 PUT 요청이 표시되므로 올바르게 작동하려면 'POST'대신 'PUT'으로 변경해야합니다. 보기에 양식을 표시하면 변경 사항을 자세히 보여줍니다.