views:

77

answers:

1

<% count = 1 %> <% for question in @questions % <%=count%>. <%= question.title if question.title%> <% for response in @response %> <% if response.question_id.eql?(question.id) %> <%=radio_button(count, :voting, :count_modification) %> <%= response.nomination %> <% end % <% end % <% count += 1 %> <% end %>

This is my whole code to implment the survey in views. if i give the count as third argument in radio button i cant select answer for each question. i can select only one answer for the whole survey.

A: 

Hello,

You can do this using virtual attributes.

attr_accessor :count_modification
before_save :modify_count

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

And in view:

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

This way, the votes won't be updated than after the model is saved.

Vlad Zloteanu
if i get the radio button id from loop, where i can place itex:<%=radio_button(count, :nominees, :vote_modification) %>
sts
the count value will be increased for each cycle.
sts
Modified my answer to take this into account :)
Vlad Zloteanu
what ever changes i have made, the values are not updating in database.
sts
Modified my question with my code in view
sts