dimanche 15 mai 2016

I am working on a cottage reservation system, how to decrement cottage availability based on number of cottages vacant?

how can i decrement a value from the database.. here is my form and output.. see image so you can understand my explaination....

when you see the attach image:

What i want is when i select Small Cottages and create a reservation and the avalabile/vacant small cottage must decrement (1) as well as to the other cottages..

form.html.erb

<%= form_for(@reservation) do |f| %>

<%= f.label :reservation_date %><br>
<%= f.date_select :reservation_date %>

<%= f.label :customer_name %><br>
<%= f.text_field :customer_name %>

<%= f.label :address%><br>
<%= f.text_field :address %>

<%= f.label :contact_no %><br>
<%= f.text_field :contact_no %>

<%= f.label :cottage_class %><br>
<%= f.select :cottage_id, options_for_select( Cottage.all.map { |g| [g.name, g.id]}) %>

<%= f.submit %>
<% end %> 

Form and list of cottages existing on the database

Aucun commentaire:

Enregistrer un commentaire