title: uninitialized constant while seeding
body: <p>Trying to seed using Ruby on Rails in ubuntu and postgresql (<code>sudo rake db:seed</code>) and it keeps throwing an <code>uninitialized constant</code> error. This is what I'm getting:</p>
  
  <pre><code>boris@alpha:~/Desktop/wikiful$ sudo rake db:seed --trace
  [sudo] password for boris: 
  ** Invoke db:seed (first_time)
  ** Execute db:seed
  ** Invoke db:abort_if_pending_migrations (first_time)
  ** Invoke environment (first_time)
  ** Execute environment
  ** Execute db:abort_if_pending_migrations
  rake aborted!
  uninitialized constant Category::Articles
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-
  
  4.0.2/lib/active_record/inheritance.rb:125:in `compute_type'
      /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/reflection.rb:178:in `klass'
      /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/association.rb:123:in `klass'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/collection_association.rb:37:in `reader'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/associations/builder/association.rb:70:in `articles'
  /usr/local/lib/ruby/gems/2.0.0/gems/activemodel-4.0.2/lib/active_model/validator.rb:151:in `block in validate'
  /usr/local/lib/ruby/gems/2.0.0/gems/activemodel-4.0.2/lib/active_model/validator.rb:150:in `each'
  /usr/local/lib/ruby/gems/2.0.0/gems/activemodel-4.0.2/lib/active_model/validator.rb:150:in `validate'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/validations/presence.rb:5:in `validate'
  /usr/local/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:283:in `_callback_before_7'
  /usr/local/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:397:in `_run__1018118611__validate__callbacks'
  /usr/local/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:80:in `run_callbacks'
  /usr/local/lib/ruby/gems/2.0.0/gems/activemodel-4.0.2/lib/active_model/validations.rb:373:in `run_validations!'
  /usr/local/lib/ruby/gems/2.0.0/gems/activemodel-4.0.2/lib/active_model/validations/callbacks.rb:106:in `block in run_validations!'
  /usr/local/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:373:in `_run__1018118611__validation__callbacks'
  /usr/local/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:80:in `run_callbacks'
  /usr/local/lib/ruby/gems/2.0.0/gems/activemodel-4.0.2/lib/active_model/validations/callbacks.rb:106:in `run_validations!'
  /usr/local/lib/ruby/gems/2.0.0/gems/activemodel-4.0.2/lib/active_model/validations.rb:314:in `valid?'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/validations.rb:70:in `valid?'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/validations.rb:77:in `perform_validations'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/validations.rb:51:in `save'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/attribute_methods/dirty.rb:32:in `save'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/transactions.rb:270:in `block (2 levels) in save'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/transactions.rb:209:in `transaction'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/transactions.rb:270:in `block in save'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/transactions.rb:281:in `rollback_active_record_state!'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/transactions.rb:269:in `save'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/persistence.rb:37:in `create'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/persistence.rb:34:in `block in create'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/persistence.rb:34:in `collect'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/persistence.rb:34:in `create'
  /home/boris/Desktop/wikiful/db/seeds.rb:5:in `&lt;top (required)&gt;'
  /usr/local/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
  /usr/local/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `block in load'
  /usr/local/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
  /usr/local/lib/ruby/gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
  /usr/local/lib/ruby/gems/2.0.0/gems/railties-4.0.2/lib/rails/engine.rb:540:in `load_seed'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/tasks/database_tasks.rb:154:in `load_seed'
  /usr/local/lib/ruby/gems/2.0.0/gems/activerecord-4.0.2/lib/active_record/railties/databases.rake:181:in `block (2 levels) in &lt;top (required)&gt;'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `call'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `block in execute'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `each'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `execute'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
  /usr/local/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:168:in `invoke_with_call_chain'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/task.rb:161:in `invoke'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:149:in `invoke_task'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `each'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `block in top_level'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:115:in `run_with_threads'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:100:in `top_level'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:78:in `block in run'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:165:in `standard_exception_handling'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/lib/rake/application.rb:75:in `run'
  /usr/local/lib/ruby/gems/2.0.0/gems/rake-10.1.1/bin/rake:33:in `&lt;top (required)&gt;'
  /usr/local/bin/rake:23:in `load'
  /usr/local/bin/rake:23:in `&lt;main&gt;'
  Tasks: TOP =&gt; db:seed
  </code></pre>
  
  <p>This is my seeds file:</p>
  
  <pre><code># This file should contain all the record creation needed to seed the database with its default values.
  # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
  
  # Create 8 seed categories
  categories = Category.create([
                  { name: 'History'}, {name: 'Biology'}, {name: 'Literature'},
                  { name: 'Mathematics'}, { name: 'Music Theory'}, { name: 'Computer Science'},
                  { name: 'Sociology'}, {name: 'Chemistry'}
          ])
  
  # create 50 articles, with random titles, 250 words of content, and
  # randomly assign one of the categories above to each article
  for i in 0..49
          title = Faker::Lorem.sentence(rand(2..10)).chomp('.')
          content = Faker::Lorem.paragraph(word_count=250)
  
          # randomly assign one of the categories we just created
          category = Category.first(offset: rand(Category.count))
          a = Article.create(title: title, content: content, categories: [category,])
  end
  </code></pre>
  
  <p>category model:</p>
  
  <pre><code>class Category &lt; ActiveRecord::Base
  
      validates :name, presence: true
      validates :name, uniqueness: true
  
      has_many :article_categories
      has_many :articles, through: :article_categories
  end
  </code></pre>
  
  <hr>
  
  <p>articlecategory model:</p>
  
  <pre><code>class ArticleCategory &lt; ActiveRecord::Base
      belongs_to :articles
      belongs_to :categories
  end
  </code></pre>
  
  <hr>
  
  <p>article model:</p>
  
  <pre><code>class Article &lt; ActiveRecord::Base
      belongs_to :user
  
      validates :title, presence: true
      validates :content, presence: true
  
      has_many :article_categories
      has_many :categories, through: :article_categories
  
  end
  </code></pre>
  
  <p>advice
  thank you</p>