Rails路线歧义

时间:2019-04-11 23:47:07

标签: ruby-on-rails routes

轨道版本:5.2.3 Ruby版本:2.0.4

在下面,我使用有关post的问题来克服对get施加的大小限制。最终与#show冲突,我不知道如何消除它们的歧义。

routes.rb

require 'sidekiq/web'

Rails.application.routes.draw do
    concern :with_datatable do
      post 'datatable', on: :collection
    end
    resources :organizations, concerns: [:with_datatable]
    mount Sidekiq::Web, at: "/ninjas"
end

我的路线如下:

  datatable_organizations POST   /organizations/datatable(.:format)                                                       organizations#datatable
            organizations GET    /organizations(.:format)                                                                 organizations#index
                          POST   /organizations(.:format)                                                                 organizations#create
         new_organization GET    /organizations/new(.:format)                                                             organizations#new
        edit_organization GET    /organizations/:id/edit(.:format)                                                        organizations#edit {:id=>/[0-9]+/}
             organization GET    /organizations/:id(.:format)                                                             organizations#show {:id=>/[0-9]+/}
                          PATCH  /organizations/:id(.:format)                                                             organizations#update {:id=>/[0-9]+/}
                          PUT    /organizations/:id(.:format)                                                             organizations#update {:id=>/[0-9]+/}
                          DELETE /organizations/:id(.:format)                                                             organizations#destroy {:id=>/[0-9]+/}
              sidekiq_web        /ninjas                                                                                  Sidekiq::Web
       rails_service_blob GET    /rails/active_storage/blobs/:signed_id/*filename(.:format)                               active_storage/blobs#show
rails_blob_representation GET    /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
       rails_disk_service GET    /rails/active_storage/disk/:encoded_key/*filename(.:format)                              active_storage/disk#show
update_rails_disk_service PUT    /rails/active_storage/disk/:encoded_token(.:format)                                      active_storage/disk#update
     rails_direct_uploads POST   /rails/active_storage/direct_uploads(.:format)                                           active_storage/direct_uploads#create

导航到路由,/ organizations / datatable.json会产生此错误: OrganizationsController#show is missing a template for this request format and variant. 它认为/organizations/datatable.json/organizations/:id/show的匹配项,尽管有明确的/organizations/datatable(.:format)路线

这是我的控制器:

class OrganizationsController < ApplicationController
    def index
        @title              = "Organizations"
        @page_description   = "Organization data warehouse"
        @page_icon          = "institution"
        @organization       = Organization.new
        @load               = {data_table: true}

      respond_to do |format|
        format.html
        format.json { render json: OrganizationDatatable.new(params) }
      end

    end
    def datatable
        respond_to do |format|
            format.json { render json: OrganizationDatatable.new(params) }
        end
    end
    def get_raw_records
        Organization.all
    end
    def create

    end
    def edit

    end
    def destroy

    end
    def show

    end
    def update

    end
    def new

    end
end

完整的错误文字:

ActionController::UnknownFormat - OrganizationsController#show is missing a template for this request format and variant.

request.formats: ["text/html"]
request.variant: []

NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.

我在这里想念什么?

0 个答案:

没有答案