我在我的数据库中添加了'问题'表...当我迁移它时...一切似乎都很好。 但是当我进入rails控制台时......它告诉我'NameError:uninitialized constant Question'
我错过了什么?这是我的迁移输出,迁移文件数据和rails控制台错误。我是Rails的初学者所以请原谅我的noobness。
所以我在我的rake db:migrate ...
之后得到了这个 Zach:FundAnEd zach$ rake db:migrate
== DropQuestionTable: migrating ==============================================
-- drop_table(:questions)
-> 0.0490s
== DropQuestionTable: migrated (0.0492s) =====================================
== CreateQuestions: migrating ================================================
-- create_table(:questions)
-> 0.0161s
-- add_index(:questions, :scholarship_id)
-> 0.0254s
== CreateQuestions: migrated (0.0417s) =======================================
这是我的迁移文件内容......
class CreateQuestions < ActiveRecord::Migration
def change
create_table :questions do |t|
t.string :question_type
t.references :scholarship
t.string :question_title
t.timestamps
end
add_index :questions, :scholarship_id
end
end
这是我得到的错误......
NameError: uninitialized constant Question
from (irb):1
from /Users/zach/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/lib/rails/commands/console.rb:47:in `start'
from /Users/zach/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
from /Users/zach/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
我做错了什么?我错过了什么?
答案 0 :(得分:4)
首先,你必须确保你有一个问题模型,如果你有它,那么请确保你遵循了正确的命名约定,ruby on rails上的模型是单数意味着模型名称将是“问题”而不是“问题”。希望它会有所帮助