Hussein.
Hussein.

Reputation: 179

rake db:seed NameError: uninitialized constant Exercice in rails console

I am working on a Course app to learn language. I migrated numerous models as Course, Chapter and Item (using acts_as-active_record gem). Items is actable and Lesson, Exercise and Exam are act_as Item. I create a seed like this :

rails = Course.create(name: "Ruby On Rails")

models = rails.chapters.create(name: "Models")

# first item is a lesson
models.items << Lesson.create(name: "What is Active Record?", content: "Lesson content here")

# then 2 exos
models.items << Exercise.create(name: "The Active Record pattern", content: "Exo about active record pattern")
models.items << Exercise.create(name: "Object Relational Mapping", content: "Exo about ORM")
models.items << Exercise.create(name: "Active Record as an ORM Framework", content: "Exo about ORM")

# a second lesson
models.items << Lesson.create(name: "Convention over Configuration in Active Record", content: "Lesson content here")

# 3 exos
models.items << Exercise.create(name: "Naming Conventions", content: "Exo about naming convention")
models.items << Exercise.create(name: "Schema Conventions", content: "Exo about schema convention")

# a summary lesson
models.items << Lesson.create(name: "Model summary", content: "Lesson content here")

# an exam
models.items << Exam.create(name: "Rails Models exam", content: "Exam content here")


# You can go to next course with : next_item = Course.first.chapters.first.items.first.lower_item
# Then go to next chapter with: next_item.chapter.lower_item

But in my rails console rake db:seed I have an error which notifies rake aborted! NameError: uninitialized constant Exercice ../db/seeds.rb:19:in <top (required)>' -e:1:in' Tasks: TOP => db:seed

I really don't know what is the error. Maybe Is there a relation with acts_as-active_record?

Here are the models :

class Course < ActiveRecord::Base 
has_many :chapters, -> { order(position: :asc) } 
validates_presence_of :title 
end 

class Chapter < ActiveRecord::Base 
acts_as_list scope: :course 
belongs_to :course 
has_many :items, -> { order(position: :asc) } 
validates_presence_of :title 
end

class Item < ActiveRecord::Base 
actable 
belongs_to :chapter 
acts_as_list scope: :chapter 
validates_presence_of :title 
end 

class Lesson < ActiveRecord::Base 
acts_as :item 
end 

class Exercise < ActiveRecord::Base 
acts_as :item 
end



class Exam < ActiveRecord::Base 
 acts_as :item 
end

The whole seed is here.

Upvotes: 0

Views: 1865

Answers (1)

apebeast
apebeast

Reputation: 368

The class Exercice and Exercise do not match.

models.items << Exercice.create(name: "The Active Record pattern", content: "Exo about active record pattern")

class Exercise < ActiveRecord::Base 
  acts_as :item 
end

Upvotes: 1

Related Questions