0

requests/index.html.erb にアクセスするときの問題は次のとおりです。

ルーティング エラー

{:action="cancel", :controller="requests"} に一致するルートはありません

index.html.erb:

<%= link_to "Cancel", cancel_request_path %>

ルート.rb:

 resources :requests do
   get 'cancel', on: :member
 end

requests_controller.rb:

 def cancel
   request = Request.find(params[:id])
   request.update_attributes(stage: "Cancelled")
   redirect_to root_path
 end

私は何が欠けていますか?

4

2 に答える 2

1

修理済み。index.html.erb でこれを変更する必要がありました。

<%= link_to "Cancel", cancel_request_path(request.id) %>

オブジェクトのすべての属性がパラメーターでアクションに渡されると思っていましたが、アクションに渡すパラメーターを指定する必要があると思います。

于 2012-09-21T18:55:52.897 に答える
0

get 'cancel', :on => :member

メンバーの意味では、パスは次のようになります。

cancel_requests_path(:id=>request_id)

または単にパラメーター内の requests オブジェクト...

于 2012-09-21T18:50:50.813 に答える