Rails - Beginner wants feedback on how they've modeled their app and how to do it better.
Posted
by adam
on Stack Overflow
See other posts from Stack Overflow
or by adam
Published on 2010-05-03T04:49:30Z
Indexed on
2010/05/03
4:58 UTC
Read the original article
Hit count: 159
ruby-on-rails
|model
I think the way I've modelled my app is a bit fishy and i need to rejig things, im just not sure how. I've already re-jigged and refactored before. It took a long time ( I'm a beginner ) and I'm hesitant to it again in case i head off in the wrong direction again.
Basic Idea, user can submit an answer, another user can mark it correct or incorrect. If incorrect they have to write the correct answer. Users can view their and everybody else's correct and incorrect answers.
So I did it this way
class Answer
has_one: correction
end
class Correction
belongs_to :answer
end
when a user marks an answer as correct, I set checked_at:DateTime and checked_by_id:integer on the Answer object to keep track of who checked the answer and when.
For incorrect answers I create a correction object which holds the correct answer and again checked_by and checked_at details.
I don't like this because I have checked_by and checked_at in both models. It just doesn't sit right.
Possible solutions are:
Create a third model such as VerifiedAnswer and move the checked_by/at attributes to that. It will handle the situtation where an answer is marked correct.
Or are these models thin enough (they dont have any other attributes) that I can just have one model ( Answer ) that has all the attributes to store all this information?
© Stack Overflow or respective owner