2012-09-21 147 views
0

这里的问题,访问请求时/ index.html.erb:路由错误 - 无路由匹配

路由错误

没有路由匹配{:动作=> “取消”,:控制器= > “请求”}

index.html.erb:

<%= link_to "Cancel", cancel_request_path %> 

routes.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 

我缺少什么?

回答

0

get 'cancel', :on => :member

在成员的手段,你的路径是这样的:

cancel_requests_path(:id=>request_id) 

或者干脆请求参数对象...

1

固定。我只是需要改变这在我index.html.erb:

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

我以为对象的所有属性将得到传递给PARAMS的动作,但我想我必须指定PARAMS通过行动。

相关问题