简体   繁体   中英

NameError: uninitialized constant in rails console

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM