0

컨트롤러에서 올바른 동작을 가리키는 버튼을 가져 오는 데 문제가 있습니다. 내 쇼보기는 다음과 같은 버튼이 있습니다버튼이 컨트롤러에서 잘못된 동작을 가리 킵니다.

<%= button_to "Submit for Approval", {action: "submit", :id => @ecn.id} %> 
<%= button_to "Close ECN", {action: "close", :id => @ecn.id}, :onclick => "return confirm('Once an ECN is closed it can no longer be edited, are you sure you want to close this ECN?')" %> 

내 컨트롤러는 다음 두 가지 작업이 있습니다

def submit 

    @ecn = Ecn.find(params[:id]) 
    @email_list = EmailList.all 

    respond_to do |format| 
     EcnNotifier.submit_engineering(@ecn).deliver if @ecn.distribute_engineering? 
     EcnNotifier.submit_purchasing(@ecn).deliver if @ecn.distribute_purchasing? 
     EcnNotifier.submit_manufacturing(@ecn).deliver if @ecn.distribute_manufacturing? 
     EcnNotifier.submit_qantel(@ecn).deliver if @ecn.distribute_qantel? 
     EcnNotifier.submit_planning(@ecn).deliver if @ecn.distribute_planning? 
     format.html { redirect_to ecns_url, alert: "Ecn has been submitted for approval." } 
     format.json { render json: @ecns } 
    end 
    end 

    def close 
    @ecn = Ecn.find(params[:id]) 
    @ecn = @ecn.close_status 

    respond_to do |format| 
     EcnNotifier.close_engineering(@ecn).deliver if @ecn.distribute_engineering? 
     format.html { redirect_to ecns_url, alert: "Ecn has been closed. A confirmation email has been sent to the appropriate personnel." } 
     format.json { render json: @ecns } 
    end 
    end 

내가 제출 버튼 "승인을 위해 제출"조치를 클릭하면 예상대로 실행됩니다. "Close ECN"버튼을 클릭하면 경고가 예상대로 나타나지만 닫기 작업보다는 제출 작업이 처리됩니다.
Started POST "/ecns/index?id=34" for 127.0.0.1 at 2013-11-03 11:53:02 -0700 
    Processing by EcnsController#submit as HTML 
    ... 

그래서 나는 그것이 잘못된 행동을 호출하는 것을 볼 수 있습니다 : 나는 "닫기 ECN"버튼을 클릭하면 내 개발 로그에 다음 보여줍니다. 나는 이것이, 내가 라우팅에 대해 너무 많이 알고하지 않는 원인이 무엇인지 잘 모르겠지만, 여기에 내 노선뿐만 아니라 파일 : 나는 두 가지 작업을 만들 때
Engdb::Application.routes.draw do 

    resources :email_lists 

get 'home' => 'home#index' 
get 'logout' => 'sessions#destroy' 
get 'login' => 'sessions#new' 
post 'login' => 'sessions#create' 
delete 'logout' => 'sessions#destroy' 

    get "login/index" 

    get "sessions/new" 

    get "sessions/create" 

    get "sessions/destroy" 

    resources :users 

    get "home/index" 

    resources :ecns 

    resources :revisions 

    resources :drawings 

    resources :home 

match 'ecns/index' => 'ecns#submit' 
match 'ecns/index' => 'ecns#close' 

내가이 "일치"라인을 추가 . 어떤 아이디어?

답변

1

을 문제는 당신의 경로이다 ecns#submitecns#close의 경로와 HTTP 동사가 동일해야합니다.

레일이 경로를 처리하는 방법은 routes.rb에서 위에서 아래로 이동하고 요청과 일치하는 첫 번째 경로를 찾으면 중지합니다. 따라서 ecns/index에 대한 요청은 항상 ecns#submit으로 전송됩니다. 경로가 동일하면 라우터가 어떤 작업을 전송할지 알 수 있습니까?

ecns#close에 대해 다른 경로를 지정하거나 각 작업에 대해 서로 다른 HTTP 동사, 에 대한 같은 #submit에 대한 postdelete를 지정하십시오.

0

가까운 행동 경로의 경로를 사용하여 시도하고 (대부분 PUT 대 POST)를 사용하면 경로에 따라 적절한 HTTP 동사를 사용하고 확인하십시오

<%= button_to "Close ECN", {:url => <close_path>, :method => <:put/:post>, :id => @ecn.id}, :onclick => "return confirm('Once an ECN is closed it can no longer be edited, are you sure you want to close this ECN?')" %>