I am using Rails (3.2.5 with ruby 1.9.3) and mongodb with mongoid. I'd like to give the user the option to check weekdays. Therefore I have a field with type hash in my controller:
field :wochentage, :type => Hash, default: { :mo => 0,
:di => 0,
:mi => 0,
:dn => 0,
:fr => 0,
:sa => 0,
:so => 0
}
The problem is that I cannot get this to work in the web form:
<% for d,v in @timetable.wochentage %>
<td><%= f.check_box :wochentage[d]%></td>
<% end %>
The error I get is:
can't convert Symbol into Integer
Can anyone please point me to the right direction? Thanks in advance, Sven
OK, a little step further: with the fields_for form helper I got closer:
<%= f.fields_for :wochentage do |w| %>
<td><%= w.check_box :mo %></td>
<td><%= w.check_box :di %></td>
<td><%= w.check_box(:mi, checked_value: "1", unchecked_value: "0") %></td>
<td><%= w.check_box :dn %></td>
<td><%= w.check_box :fr %></td>
<td><%= w.check_box :sa %></td>
<td><%= w.check_box :so %></td>
<% end %>
With this code I can set the weekday. But it won't read it from the DB, if I want to edit it though it is stored correctly: Wochentage: {"mo"=>"0", "di"=>"0", "mi"=>"1", "dn"=>"0", "fr"=>"0", "sa"=>"0", "so"=>"0"}
In the edit form all checkboxes are unchecked. So how can I make the checkbox show up in the correct status?
Thanks, S