Rails: getting nil values in hidden field -
i'm getting nil values when i'm using hidden field
<%= form_for @hour |f| %> <%= f.hidden_field "days[]", :value => "sunday" %> <%= f.hidden_field "days[]", :value => "monday" %> <%= f.hidden_field "days[]", :value => "tuesday" %> <%= f.hidden_field "days[]", :value => "wednesday" %> <%= f.hidden_field "days[]", :value => "thursday" %> <%= f.hidden_field "days[]", :value => "friday" %> <%= f.hidden_field "days[]", :value => "saturday" %> <% end %>
my parameters:
"days"=>[nil,nil,nil,nil,nil,nil,nil]
am doing hidden fields wrong?
thanks
check if below code helps.
<%= form_for @hour |f| %> <%= f.hidden_field "days[0]", :value => "sunday" %> <%= f.hidden_field "days[1]", :value => "monday" %> <%= f.hidden_field "days[2]", :value => "tuesday" %> <%= f.hidden_field "days[3]", :value => "wednesday" %> <%= f.hidden_field "days[4]", :value => "thursday" %> <%= f.hidden_field "days[5]", :value => "friday" %> <%= f.hidden_field "days[6]", :value => "saturday" %> <% end %>
params:
parameters: {"utf8"=>"√",authenticity_token"=>"m84ly0ok8nwkzqv2zgzvtp1trosz3m0oll7w5w5pk+i=", "hour"=>{"days"=>{"0"=>"sunday", "1"=>"monday", "2"=>"tuesday", "3"=>"wednesday", "4"=>"thursday", "5"=>"friday", "6"=>"saturday"}}, "commit"=>"create hour "}
updated
dynamic :
<%= form_for @hour |f| %> <%= f.hidden_field "days][", :value => "sunday" %> <%= f.hidden_field "days][", :value => "monday" %> <%= f.hidden_field "days][", :value => "tuesday" %> <%= f.hidden_field "days][", :value => "wednesday" %> <%= f.hidden_field "days][", :value => "thursday" %> <%= f.hidden_field "days][", :value => "friday" %> <%= f.hidden_field "days][", :value => "saturday" %> <% end %>
output:
parameters: {"utf8"=>"√", "authenticity_token"=>"jxcdmsokjclxu4ysswp/gw19ejy4ty3nwdbw/l/+lru=", "user"=>{"hour"=>["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]}, "commit"=>"create hour"}
Comments
Post a Comment