Reputation: 19
How can I make 10 or more than 10 check box by a for loop
This is my code
In view.html.erb
<% (0...100) do |i| %>
<%= f.check_box :chkbox_ary[i], {:checked=>false, :style => "width: 20px; height: 20px;"} %>
<%= f.label "checkbox" %>
<% end %>
And in model
attr_accessor :chkbox_ary
def initialize(attributes = {})
@chkbox_ary = []
end
I think this is OK, but I always get error
Internal Server Error
expected Array (got Rack::Utils::KeySpaceConstrainedParams) for param `travel'
How can I do to get my purpose or have some reference for me? Thanks
Upvotes: 0
Views: 366
Reputation: 17735
Your loop is missing an iterator:
(0...100).each do |i|
And you cannot use an index on a symbol - use the name of the array, and interpolate the index variable:
f.check_box "chkbox_ary[#{i}]" #...
Upvotes: 1