-1

I don't know why it is printing out an array. I used the same method for another checkbox and it doesn't print out an array.

This is the code for the view

 <%= f.label "Category: " %>
 <%= Category.all.each do |category| %>
 <%= check_box_tag "course[category_ids][]", category.id %>
 <%= category.cat_name %>
 <% end %>

and this is what it prints:

Programming [#<Category id: 1, cat_name: "Programming", created_at: "2017-05-25 02:25:24", updated_at: "2017-05-25 02:25:24">]

Is there a way to remove the array?

JunitHelp
  • 53
  • 4

1 Answers1

1

You're printing Programming [#<Category id: 1, cat_name: "Programming"...] because you're using <%= ... %> instead <% ... %>, that's why you're printing the result of Category.all.each.

You can remove the = in your Category.all and that'll be as you want it.

Also I'd recommend you to create that as a variable in your controller and then to pass it to the view.

Sebastian Palma
  • 29,105
  • 6
  • 30
  • 48