Reputation: 35
I'm adding a 'questions' table to my database...when I migrated it...everything seemed fine. BUT when I go into rails console...it tells me 'NameError: uninitialized constant Question'
what am I missing? Here is my migration output, migration file data, and rails console error.
I'm a beginner at Rails so please forgive my noobness.
So I got this after my 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) =======================================
and this is my migration file content...
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
AND here is the error I'm getting....
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>'
What am I doing wrong? What am I missing?
Upvotes: 3
Views: 4836
Reputation: 2385
First of all you have to make sure you have a Question model, plus if you have it then make sure you have followed proper naming conventions, models in ruby on rails are singular means the model name would be "Question" not "Questions". hope it would help
Upvotes: 5