This code works, but I think the solution is ugly, please advise.
User updates a standard form_for, the form is re-rendered with
checkboxes next to each updated line. The user is expected to select
up to 3 checkboxes which will be saved in the user model under columns
(top_1of3, top_2of3, top_3of3).
View:
<% form_tag :action => ''top_three'' do %>
<% for line in @updated_info do %>
<%= check_box_tag( "choice_" + @updated_info.index(line).to_s ,
line ) %><%= line %><br/>
<% end %>
<%= submit_tag %>
<% end %>
----------------------------------------------------------------------------------------------------------------------------
Controller:
choices = {}
for i in 0..50
choice = "choice_" + i.to_s
choice = choice.intern
if !params[choice].nil? and choices["top_1of3"].nil?
choices["top_1of3"] = params[choice]
elsif !params[choice].nil? and choices["top_2of3"].nil?
choices["top_2of3"] = params[choice]
elsif !params[choice].nil? and choices["top_3of3"].nil?
choices["top_3of3"] = params[choice]
end
end
if @user.update_attributes(choices)
......
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---