2009-07-30 78 views
1

这是我的全部代码implment在意见调查。如果我把计数作为单选按钮中的第三个参数,我不能为每个问题选择答案。我可以为整个调查只选择一个答案。基于单选按钮选择增加字段值

回答

0

您可以使用虚拟属性来做到这一点。

attr_accessor :count_modification 
before_save :modify_count 

def modify_count() 
    self.count += @count_modification if @count_modification 
end 

,并考虑:

<%= radio_button("my_model", "count_modification", "1") %> Add one vote 
<%= radio_button("my_model", "count_modification", "2") %> Add 2 votes 
<%= radio_button("my_model", "count_modification", "3") %> Add 3 votes 

这样一来,票不会比模型保存后更新。

+0

如果我得到从循环,其中i可以将它放在离 的单选按钮ID: <%= radio_button(计数,:提名,:vote_modification)%> – sts 2009-07-30 11:28:13