我正在尝试为我的复选框添加一个值。但是当我试图通过检查元素查看它时它不存在。这是我的做法。
数据库选择:
@amenities = AmenitiesAndFeatures.where(is_amenities: true).order("name ASC")
<% x=@amenities.size/2 %>
<% @amenities.each_with_index do |amenity,i|%>
<% if i < x %>
<p><input type="checkbox" name="amenitiesAndFeaturesCheckbox" class="listing-check" value=<%@amenities[i].id%>>
<%= @amenities[i].name %></p>
<% end %>
<%end%>
有任何想法吗?并且以相同的名称命名所有复选框是否正确,以便获得所有选中的复选框。我只需要这样做吗?
objects["amenitiesAndFeaturesCheckbox"].each do |amenitiesAndFeatures|
listing_amenities_and_features.listing_id = listing_id
listing_amenities_and_features.amenities_and_features_id = amenitiesAndFeatures
end