對基本問題表示歉意,但我正在嘗試創建一個端點,以便我可以通過我的 VueJs 前端通過 Fetch 在我的后端創建一個 TranslationApi,所以我需要創建一個可以插入的端點。我正在嘗試創建一條路線來實作這一點,但是當我運行時,bin/rails routes | grep CcApiController我收到以下錯誤:
ArgumentError: 'CcApiController' is not a supported controller name. This can lead to potential routing problems. See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use
我已閱讀鏈接的檔案,但我無法解決此問題,有人可以解釋我在這里出錯的地方嗎?我將鏈接我在下面更改的檔案:
cc_apis_controller.rb
module Panel
class CcApisController < CcenterBaseController
def index
run Ccenter::Adapters::Zendesk::TranslationApi.call(2116449)
end
end
end
panel_routes.rb
def draw_api_routes
resources: CcApiController
end
路由檔案
Rails.application.routes.draw do
resources :CcApiController, only: [:index]
end
我需要為以下物件創建路由的 API 方法:
def make_request
response = Faraday.post('https://api.deepl.com/v2/translate', auth_key: '', text: @final_ticket, target_lang: 'DE', source_lang: 'EN')
if response.status == 200
body = response.body
message_element = body.split('"')[-2]
return message_element
else
raise InvalidResponseError unless response.success?
end
end
uj5u.com熱心網友回復:
答案很簡單。路由名稱是snake_case,匹配控制器的檔案名只是省略_controller后綴。在你的情況下是
Rails.application.routes.draw do
namespace :panel do
resources :cc_apis, only: %i[index]
end
end
有關更多資訊,請查看此檔案和本文。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/358365.html
標籤:红宝石轨道
