# What's a simpler way of doing this form collection?

**URL:** <https://www.ruby-forum.com/t/whats-a-simpler-way-of-doing-this-form-collection/126755>\
**Category:** Rails\
**Created:** [January 21, 2008, 11:30pm UTC](https://www.ruby-forum.com/t/whats-a-simpler-way-of-doing-this-form-collection/126755 "2008-01-21T23:30:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yetanothergeek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/8e8cbc/32.png) [@yetanothergeek](https://www.ruby-forum.com/u/yetanothergeek)\
**Post date:** [January 21, 2008, 11:30pm UTC](https://www.ruby-forum.com/t/whats-a-simpler-way-of-doing-this-form-collection/126755/1 "2008-01-21T23:30:15Z")

</div>

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 %\>  
  
\<% 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)

```

…
