如何设置投票宝石,使其按如下方式工作。
我有以下模型类 User < ActiveRecord::Base has_many :questions end
class Question < ActiveRecord::Base
belongs_to :user
has_many :answers
end
class Answer < ActiveRecord::Base
belongs_to :question
end
使用我可以添加的 Thumbs_up gem
class User < ActiveRecord::Base
acts_as_voter
end
class Answer < ActiveRecord::Base
acts_as_voteable
end
添加投票和
validates_uniqueness_of :voteable_id, :scope => [:voteable_type, :voter_type, :voter_id]
允许每个用户投一票,但这不会阻止用户对所有答案进行投票。为了解决这个问题,我正在考虑用单选按钮替换链接(投票),这样用户只能选择一个答案。如何在模型(数据库级别)进行设置,以便当用户更新他们的答案时,如下例所示
例如:
用户可以提出问题并添加朋友可以从中选择的选项(答案)列表。
which of the following programming language is easy to learn?
PHP
Java
Ruby
python
用户可以根据需要向问题添加任意数量的选项。朋友只能选择一个答案,但可以更新(更改)为新答案,在这种情况下,旧答案会在创建新答案时被删除。
输出应如下所示:
which of the following programming language is easy to learn?
Ruby(32 votes)
PHP(24 votes)
Java(13 votes)
python(9 votes)
一件事不一定是任何 gem 都会做的 Thumbs_up。