Form_for checkbox with array

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:

<% form_for @user do |f| %> <% @list_of_descriptions.each do |i| %> <% f.check_box :i %> <% end %> <% end %>
where @list_of_descriptions = @user.descriptions_of_like.split(%r{,\s*})

and get error
“undefined method `i’”

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.

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

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs