在我的restful Web服务中删除路由不起作用

时间:2015-12-01 13:28:36

标签: ruby-on-rails ruby-on-rails-3 rspec routing

我在我的restful Web服务上路由到我的删除方法时遇到问题。 我的路线设置如下:

  namespace :service do
      namespace :v1 do
        resources :surveys do
          resources :permissions, only: [:index, :create, :delete, :update]
        end
      end
    end

以下规范通过

   it "routes toya expected controller method" do
      {:get => 'service/v1/surveys/3/permissions'}.should route_to(controller: 'service/v1/permissions', action: 'index', :survey_id => "3")
   end

此规范失败

describe 'DELETE :destroy' do
    it "routes to expected controller method" do
      {:delete => 'service/v1/surveys/3/permissions'}.should route_to(controller: 'service/v1/permissions', action: 'destroy', :survey_id => "3")
    end
  end

我的控制器的片段如下

module Service
  module V1
    class PermissionsController < ApplicationController

      before_filter :authenticate_user!, :only => []

      def index
        render :json => permissions,  :each_serializer => Service::V1::PermissionSerializer
      end

 def destroy
            debugger
            # cant route to here 
            a = 1
      end

    end
  end
end

有什么建议吗?我在销毁和删除之间略有混淆,我认为这可能是我的问题的根源

1 个答案:

答案 0 :(得分:1)

你需要传递权限ID,如: -

{:delete => 'service/v1/surveys/3/permissions/permission_id'}.should route_to(controller: 'service/v1/permissions', action: 'destroy', :survey_id => "3", :id => "permission_id")