ruby-on-rails - Rails 路线消歧
问题描述
Rails 版本:5.2.3 Ruby 版本:2.0.4
在下文中,我使用对 post 的关注来克服对 get 施加的大小限制。它最终与#show 发生冲突,我不知道如何消除它们的歧义。
路线.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.
我在这里想念什么?
解决方案
推荐阅读
- java - 在 Java 上调用 isPresent 的最佳方式可选
- arduino - MPU6050 FIFO溢出和冻结问题
- vue.js - ion-icon 没有在 ionic vue 中显示图标
- javascript - HTML5 视频:确定视频对象的预期帧速率 (fps)?
- compiler-construction - 在 LLVM 自定义优化过程中删除指令的 Segfault
- mobile - storage.googleapis.com 我收到“您的连接不是私密的”
- c++ - 在 IBMi7.4 上尝试使用 LANGLVL(*EXTENDED0X) 编译 C++ 代码时出现 _VACPP_HASH_FUNCTION_CHECK 错误
- php - 如何排除在 pdf 和 excel 文件中导出 kartik gridview 中的某些表列?
- python - 计算 RGB 图像的百分比减少
- docker - Docker 容器未启动以创建 docker 文件