Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 Rails 3.2 和 4。
我有一个调查,我想验证每个问题都有 2 到 5 个答案。调查有_很多问题,问题有_很多答案,属于调查。答案属于问题。
我该怎么做?
在问题模型中
validate :answer_count def answer_count self.errors[:base] << "Can have answers only between 2 and 5" if answers.length<1 || answers.length>5 end