2009-07-30 7 views

Antwort

0

Sie können dies mit virtuellen Attributen tun.

attr_accessor :count_modification 
before_save :modify_count 

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

Und im Blick:

<%= 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 

Auf diese Weise werden die Stimmen nicht als aktualisiert werden, nachdem das Modell gespeichert wird.

+0

, wenn ich die Optionsfeld-ID aus Schleife bekommen, wo ich es ex platzieren können: <% = radio_button (Anzahl,: Nominiert: vote_modification)%> – sts

+0

die Zählwert wird für jeden Zyklus erhöht werden. – sts

+0

Meine Antwort geändert, um dies zu berücksichtigen :) –

Verwandte Themen