views:

96

answers:

0

I return a form partial on a set of info like so...

Room1         Monday    Tuesday   Wednesday     No. ppl
Blue Room     $55       $55       $55           Select_tag (0-8)
Double Bed    $100      $110      $200          Select_tag (0-8)

<% for room in @rooms %>
<tr>
    <th scope="row" class="<%= cycle("spec", "specalt") -%>"><%=h room.name %></td>
    <td class="<%=current_cycle%>"><%=h room.day1 %></td>
    <td class="<%=current_cycle%>"><%=h room.day2 %></td>
    <td class="<%=current_cycle%>"><%=h room.day3 %></td>
    <td class="<%=current_cycle%>"><%=h room.day4 %></td>
    <td class="<%=current_cycle%>"><%=h room.day5 %></td>
    <td class="<%=current_cycle%>"><%=h room.day6 %></td>
    <td class="<%=current_cycle%>"><%=h room.day7 %></td>
    <td class="<%=current_cycle%>"><%= select_tag("room[#{room.id}]", options_for_select(0..room.spots,0)) %></td>

</tr>
<% end %>

like so... the partial pulls down up 20 rooms like this... and up to 7 nights in a row... the only data submitted thru the form is a hidden_field for the Hotel_id which is for all of the rooms and the select_tag for the number of rooms they would like for all the nights.

The select_tag currently has a name eq to the ID of the specific room... ie room[room_id] (room[1234] and a value of set by the drop down... typically 0-8.

Is there a better way to handle this? It feels a bit wrong needing both the keys of the hash it returns and the value... and then trying to handle it.

First off i'm deleting the results from the form which are a zero value: @cart.delete_if {|k, v| v == "0" }

then setting the session for the @cart.keys and the @cart.values.... for both sides of the hash. Is there a better way?