Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在控制器中调用类方法时未初始化的常量_Ruby On Rails_Routing - Fatal编程技术网

Ruby on rails 在控制器中调用类方法时未初始化的常量

Ruby on rails 在控制器中调用类方法时未初始化的常量,ruby-on-rails,routing,Ruby On Rails,Routing,我有一个叫做设备的类。它有一个模型device.rb 我已经设置了路由,以便从两个不同的路径调用相同的控制器。i、 e.路径: /driver_api/v1/devices 及 两者都调用以下控制器: /user_api/v1/devices class UserApi::V1::DevicesController < ApplicationController Devise.method_name(input) end 在my routes.rb中,我有: names

我有一个叫做设备的类。它有一个模型device.rb

我已经设置了路由,以便从两个不同的路径调用相同的控制器。i、 e.路径:

/driver_api/v1/devices

两者都调用以下控制器:

/user_api/v1/devices
class UserApi::V1::DevicesController < ApplicationController

      Devise.method_name(input)
end
在my routes.rb中,我有:

namespace :driver_api do
  namespace :v1 do
     resources :devices, :only => [:create], controller: '/user_api/v1/devices'
  end
end

namespace :sender_api do
  namespace :v1 do
     resources :devices, :only => [:create], controller: '/user_api/v1/devices'
  end
end
现在,在我的设备控制器中,我尝试调用一个设备类方法。i、 e.在我的控制器中:

/user_api/v1/devices
class UserApi::V1::DevicesController < ApplicationController

      Devise.method_name(input)
end

为什么会出现此错误?

因为您编写了
design
而不是
Device
,这可能是一个很好的理由

如果这只是问题中的一个典型例子,这里还有另一个选择。 有时,当类以您的方式定义时,会出现某种命名问题(我忽略了发生这种情况的原因)

尝试通过定义模块来分解类作用域:

module UserApi
  module V1
    class DevicesController < ApplicationController
      # rest
    end
  end
end
moduleuserapi
模块V1
类DeviceController<应用程序控制器
#休息
结束
结束
结束

试试
::设计。方法\u名称(输入)
设备还是设计?您的示例使用了双股。是的,那是个打字错误。问题应该是“设备”而不是“设计”。事实上,经过两个小时的尝试后,简单地重置服务器就完成了任务。然而,这是一个非常有用的替代术语,我不知道。非常有帮助。无论如何,谢谢你。