loops - Process return of select from database in erb view in ruby on rails -


i'm trying process array/list came database. here's how it:

@amenities = amenitiesandfeatures.select("name").where(is_amenities: true).order("name asc")  div class="e-float-left">     <%(@amenities.each) |amenities|%>         <p><input type="checkbox" class="listing-check">         <%=amenities.name%></p>     <%end%> </div></td> 

i can display data sequentially using code. want add logic it.

what want accomplish create loop loop in .net. how can construct in ror this?

var x = amenities.length for(int = 0; <= x/2;i++) {     <p><input type="checkbox" class="listing-check">     amenities.name[i]</p> } 

i doing on erb view. i'm trying pull name column on amenitiesandfeatures , process each 1 inside loop.

please try this
x=@amenities.size/2
<% @amenities.each_with_index |amenity,i|%>
<% if <= x %>
<p><input type="checkbox" class="listing-check">
<%= @amenities[i].name %></p>
<% end %>
<%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 -