【问题标题】:Routing to delete in my restful web service is not working在我的宁静 Web 服务中删除路由不起作用
【发布时间】:2015-12-01 13:28:35
【问题描述】:

我在路由到我的 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

我的控制器的sn-p如下

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

有什么建议吗?我对销毁和删除有点困惑,我认为这可能是我的问题的根源

【问题讨论】:

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


    【解决方案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")
    

    【讨论】:

    • 我认为您可以不指定 id 并通过 id 数组发送,我猜有点乐观
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    • 1970-01-01
    • 2018-04-21
    • 1970-01-01
    • 2011-01-27
    • 1970-01-01
    相关资源
    最近更新 更多