ruby on rails - Assign value to checkbox from database pull -


i'm trying add value checkbox. it's not there when i'm trying view via inspect element. here's how it.

database select:

@amenities = amenitiesandfeatures.where(is_amenities: true).order("name asc")  <% x=@amenities.size/2 %> <% @amenities.each_with_index |amenity,i|%>   <% if < x %>     <p><input type="checkbox" name="amenitiesandfeaturescheckbox" class="listing-check" value=<%@amenities[i].id%>>     <%= @amenities[i].name %></p>   <% end %> <%end%> 

any ideas? , right name checkboxes same name in order checked checkboxes . need this?

objects["amenitiesandfeaturescheckbox"].each |amenitiesandfeatures|     listing_amenities_and_features.listing_id = listing_id     listing_amenities_and_features.amenities_and_features_id = amenitiesandfeatures end 

you need use <%= @ value attribute, not <%:

<input type="checkbox" ... value=<%= @amenities[i].id %>> 

also, within loop, there no need use @amenities[i], , therefore no need use each_with_index, since that's amenity during each iteration of loop. can rid of x variable , use take:

<% @amenities.take(@amenities.size/2).each |amenity| %>   <p>     <input type="checkbox" name="amenitiesandfeaturescheckbox" class="listing-check" value=<%= amenity.id %>>     <%= amenity.name %>   </p> <%end%> 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -