# form\_for checkbox with array

**URL:** <https://discuss.rubyonrails.org/t/form-for-checkbox-with-array/59125>\
**Category:** rubyonrails-talk\
**Created:** [May 23, 2011, 7:16pm UTC](https://discuss.rubyonrails.org/t/form-for-checkbox-with-array/59125 "2011-05-23T19:16:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [May 23, 2011, 7:16pm UTC](https://discuss.rubyonrails.org/t/form-for-checkbox-with-array/59125/1 "2011-05-23T19:16:55Z")

</div>

Hello. I have a model Profile with an attribute named 'descriptions\_of\_like'. 'desctiptions\_of\_like' - is a string, which I convert into an array for working with them and before saving in table convert into a string. (It's a not a best way, i think, but the first thing that comes to mind). How can i manage this lisk of descriptions with form\_for? I write this:

\<div id = 'descriptions'\> &nbsp;&nbsp;\<% form\_for @user do |f| %\> &nbsp;&nbsp;&nbsp;&nbsp;\<% @list\_of\_descriptions.each do |i| %\> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<% f.check\_box :i %\> &nbsp;&nbsp;&nbsp;&nbsp;\<% end %\> &nbsp;&nbsp;\<% end %\> \</div\> where @list\_of\_descriptions = @user.descriptions\_of\_like.split(%r{,\s\*})

and get error "undefined method `i'"

---

<div class="post-metadata">

**Author:** ![Tim\_Shaffer2](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@Tim\_Shaffer2](https://discuss.rubyonrails.org/u/Tim_Shaffer2)\
**Post date:** [May 23, 2011, 7:55pm UTC](https://discuss.rubyonrails.org/t/form-for-checkbox-with-array/59125/2 "2011-05-23T19:55:31Z")

</div>

When you do f.check\_box(:i) Rails expects the model for the form instance (in this case, User) to have an attribute called “i”.

You can use the “check\_box\_tag” helper to generate a check box that is not tied to a model.

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [May 23, 2011, 8:01pm UTC](https://discuss.rubyonrails.org/t/form-for-checkbox-with-array/59125/3 "2011-05-23T20:01:58Z")

</div>

I've read what you posted and I'm still not sure what you are trying to do here. Start out by providing the following and use ([http://gist.github.com](http://gist.github.com)) for posting the code for readability.

Model Files: post your user.rb and profile.rb Schema: post your schema for user and profile Controller Files: post your profiles\_controller.rb

Then, answer what you are trying to do with the checkbox. And, while you are at it, review this here so you can understand how to properly write a form\_for - [http://guides.rubyonrails.org/form\_helpers.html](http://guides.rubyonrails.org/form_helpers.html)

You'll find form\_for in section 2.2.

After you post that, just provide a short summary of how you feel the logic should work with these controllers.

Example:

When going to the profiles index I expect to see the following: .. field\_one : string containing x.. .. field\_two : integer containing y.. etc..

Given this, anyone should be able to answer your question.

Thanks mate.
