Closed anastasiaalt closed 8 years ago
Anastasia: The reason you're getting this error is because there is a module named after your application. So when you did rails new quiz
, it created a module named Quiz
.
Later, you created a model named Quiz
, which means there is also a class named Quiz
. So now there are two things happening here, both with the same name. When you call Quiz.destroy_all
it finds the nearest thing called Quiz, which is the module. OH NO!
So, either rename your app, or rename the model. I suggest the model.
rake db:drop
quiz.rb
and rename it assessment.rb
, then change class Quiz
to class Assessment
in that file.Quiz
that's not module Quiz
, and replace it with Assessment
has_many :quizzes
should be has_many :assessments
, and belongs_to :quiz
should be belongs_to :assessment
, etc.Quiz
, and change quiz to assessment.Anastasia,
The password relates to the specific name of the password_digest field required by using has_secure_password
in your models. Your instructor schema shows you called the field encrypted_password
but it must be called password_digest
. Same thing with your student model and schema. This is just how Rails expects things to be done.
As for the destroy_all method coming back undefined, there's actually two separate issues here. The first, and more important is that the Rails application itself is called Quiz, so you can't have anything else called Quiz. You will need to rename this table to something else. As a secondary, the plural of quiz is quizzes with 2 "z"s. Just be sure that you are spelling pluralized forms correctly. If necessary, use the rails generators for models just to get yourself started and then add the fields in in a later migration.
Hope that helps.
-Avi
I am attempting to seed my database. After creating a database, generating migrations, and migrating the database, my next step is to seed the database. When I run rake db:seed from the command line, I get this error: https://github.com/anastasiaalt/quiz/blob/master/db/seeds.rb
Based on this error, I have been investigating my Quiz module, which looks like the below at present: https://github.com/anastasiaalt/quiz/blob/master/app/models/quiz.rb
My suspicion is the error I am getting has something to do with the way I am connecting answers and options to Quiz.
I have searched for answers on Stack Overflow and the Ruby on Rails docs for answers related to this error and have not found anything conclusive. One article pointed in the direction of models inheriting from one another rather than from ActiveRecord, e.g. Option inherits from Question or Answer inherits from Question but I did not understand when to possibly use this versus has_many: with through:
My first attempt did not have these two lines in the model but added them after research and in both instances I get the same error
If I comment out this line in the seeds file
I get this error when I attempt rake db:seed from the command line
I recognize this is a separate error connected to passwords and am still troubleshooting. I will file a separate issue if I cannot work past it.