2009-07-30 71 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

相關問題