我正在嘗試在我的 rails 應用程式中命名我的控制器。我的控制器中有:
#controllers/api/auth_controller.rb
class Api::AuthController < ApplicationController
def register
end
end
在我的路線檔案中,我有:
namespace :api do
get "auth/register", to: "api/auth#register"
end
我不斷收到錯誤:
uninitialized constant Api::Api Object.const_get(camel_cased_word) ^^^^^^^^^^ raise MissingController.new(error.message, error.name) ^^^^^
我究竟做錯了什么?
uj5u.com熱心網友回復:
它給了你這個錯誤,因為你告訴 rails 在api/里面尋找namspace :api所以它試圖找到Api::Api,你只需要洗掉apifrom api/auth#register,它會自動尋找 api,因為路線在下面namespace :api,只要做get "auth/register", to: "auth#register",你應該很好。
更多關于路由中的命名空間here
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/529722.html
標籤:轨道上的红宝石红宝石
