gpt4 book ai didi

ruby-on-rails - Rails Controller 命名空间/模块配置

转载 作者:行者123 更新时间:2023-12-04 17:02:35 25 4
gpt4 key购买 nike

我的 rails 项目中有一个模型的 API Controller 。

API Controller 如下:

#app/controllers/api/v1/airbnb/customers_controller.rb
module Api
module V1
class CustomersController < Api::V1::BaseApiController
def create
@airbnb_customer = Airbnb::Customer.new
@json_request['airbnb_customer']['client_id'] = @client.id
update_values :@customer, @json_request['airbnb_customer']
end
end
end
end

创建新 airbnb_customer时出现问题:
NameError in Api::V1::Airbnb::CustomersController#create
uninitialized constant Api::V1::Airbnb::Customer

我不知道如何在调用 Airbnb::Customer.new 时阻止应用 Api::V1 范围
任何帮助将不胜感激。

我的模型位于 app/models/airbnb.rbapp/models/airbnb/customer.rb .

最佳答案

添加::在 Airbnb 应该访问命名空间树的“根”之前,因此您应该添加

::Airbnb::Customer.new

关于ruby-on-rails - Rails Controller 命名空间/模块配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37841124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com