title: Count the amount of records are associated to another record
body: <p>In my Ruby on Rails application I am creating a cinema system, and on the bookings/new page I am allowing the user to choose the amount of seats they require through a drop down menu. But what I want to do is display the number of seats that are currently free in the screen, for example if a screen has 50 seats and 7 have been booked I want the system to display: "There are 43 seats available." I know I will need a method for this but am unsure about how I would implement it and how I would show this message. </p>
  
  <p>It is worth noting that a seat would only be booked for one showing, so it would be free for others, which means that the method would have to be able to count the amount of seats available for that showing.</p>
  
  <p>Can someone please help.</p>
  
  <p>bookings/form.html.erb:</p>
  
  <pre><code>&lt;%= form_for @booking do |f| %&gt;
      &lt;%= f.hidden_field :user_id %&gt;
      &lt;%= f.hidden_field :showing_id %&gt;
  
      &lt;%= image_tag "thor_hammer.jpg",:size =&gt; "900x250" %&gt;
      &lt;h1&gt;NEW BOOKING:&lt;/h1&gt;
      &lt;tr&gt;
          &lt;td width="350px"&gt;
              &lt;br&gt;&lt;%= f.label :seats_quantity, 'Please Select The Amount of Seats Required:' %&gt;
          &lt;/td&gt;
          &lt;td width="300px"&gt;
              &lt;br&gt;&lt;%= f.select :seats_quantity, '1'..'10' %&gt;&lt;br&gt;
          &lt;/td&gt;
          &lt;td width="300px"&gt;
              &lt;div class="actions"&gt;
                   &lt;br&gt;&lt;%= f.submit 'Book Showing' %&gt;
              &lt;/div&gt;
              &lt;br&gt;&lt;%= render "/error_messages", :message_header =&gt; "Cannot save: ", :target =&gt; @booking %&gt; 
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Screen.rb:</p>
  
  <pre><code>class Screen &lt; ActiveRecord::Base
     has_many :seats
     has_many :showings
     def screens_info
         "#{name}"
     end
  end
  </code></pre>
  
  <p>Seat.rb:</p>
  
  <pre><code>class Seat &lt; ActiveRecord::Base
      belongs_to :screen
  end
  </code></pre>
  
  <p>Booking.rb:</p>
  
  <pre><code>class Booking &lt; ActiveRecord::Base
      belongs_to :user
      belongs_to :showing
  end
  </code></pre>
  
  <p>Showing.rb:</p>
  
  <pre><code>class Showing &lt; ActiveRecord::Base
     belongs_to :film
     has_many :bookings
     belongs_to :screen
  end
  </code></pre>
  
  <p>Schema:</p>
  
  <pre><code>create_table "bookings", force: :cascade do |t|
      t.integer  "user_id"
      t.integer  "showing_id"
      t.integer  "seats_quantity"
  end
  
  create_table "screens", force: :cascade do |t|
     t.string   "name"
  end
  
  create_table "showings", force: :cascade do |t|
     t.date     "show_date"
     t.time     "show_time"
     t.integer  "film_id"
     t.integer  "screen_id"
  end
  
  create_table "seats", force: :cascade do |t|
     t.string   "row_letter"
     t.integer  "row_number"
     t.integer  "screen_id"
  end
  </code></pre>
  
  <p>It is worth noting that whilst the <code>seats</code> table contains the attributes <code>row_letter</code> and <code>row_number</code> a user IS NOT booking a specific seat, just the quantity of seats they require.</p>