【发布时间】:2012-03-09 08:34:08
【问题描述】:
您好,我遇到了命名空间冲突的问题。我有一个模型:测试和控制器 TestsController。服务器显示错误
undefined method `new' for Test:Module
我读到了这个问题rails models
在模块UserTest中添加到模型Test
module UserTest
class Test < ActiveRecord::Base
....
end
end
并添加到控制器中
class TestsController < ApplicationController
def new
@test = UserTest::Test.new
@test.questions.build
@title = "New test"
end
...
end
服务器显示错误:uninitialized constant TestsController::UserTest
阅读更多内容后,我意识到可能需要添加 require 或包含控制器。只有我不明白该怎么做。请告诉我。
【问题讨论】:
-
您的模块似乎未知,您加载了吗?
标签: ruby-on-rails ruby-on-rails-3