title: Ruby on Rails How can i display validation error message?
body: <p>My Code is working but it doesn't display error message. I need to display that creating new reservation is not valid because the table_number, @requested_time and date are already been booked.</p>
  
  <p>reservations_controller.rb</p>
  
  <pre><code>def create
    if !current_user.try(:admin?)
      @user = User.find(params[:user_id]) 
      @reservation = current_user.reservations.build(reservations_params)
      @reservation.user = @user
      @reservation.save
      redirect_to @user
    else
      @user = User.find(params[:user_id]) 
      @reservation = current_user.reservations.build(reservations_params)
      @reservation.user = @user
      @reservation.save
      redirect_to "/lists/reservationlist"
    end
  end
  </code></pre>
  
  <p>reservation.rb</p>
  
  <pre><code>class Reservation &lt; ActiveRecord::Base
  
    belongs_to :user 
    belongs_to :customer
    belongs_to :table
    belongs_to :payment
  
    validates :table_id, uniqueness: { :scope =&gt; [:requested_date, :requested_time], :message =&gt; "Reservation is not available" }
  end
  </code></pre>
  
  <p>new.html.erb</p>
  
  <pre><code>&lt;br&gt;
  &lt;%= form_for [@user, @reservation] do |f| %&gt;
    &lt;% if current_user.try(:admin?) %&gt;
      &lt;label&gt;Client Name:&lt;/label&gt;&lt;p &amp;nbsp;&gt;&lt;/p&gt;
      &lt;span class="login"&gt;
        &lt;%= f.text_field :client_name %&gt;&lt;br&gt;
      &lt;/span&gt;
      &lt;label&gt;Client Address:&lt;/label&gt;&lt;p &amp;nbsp;&gt;&lt;/p&gt;
      &lt;span class="login"&gt;
        &lt;%= f.text_field :client_address %&gt;&lt;br&gt;
      &lt;/span&gt;
      &lt;label&gt;Client Contact:&lt;/label&gt;&lt;p &amp;nbsp;&gt;&lt;/p&gt;
      &lt;span class="login"&gt;
        &lt;%= f.text_field :client_contact %&gt;&lt;br&gt;&lt;br&gt;
      &lt;/span&gt;
    &lt;% end %&gt;
  
    &lt;label&gt;Table Number:&lt;/label&gt;&lt;p &amp;nbsp;&gt;&lt;/p&gt;
    &lt;span class="table"&gt;
      &lt;%= f.select(:table_id, options_for_select( Table.all.map{ |g| [g.table_number, g.id] } ), {:class =&gt; "styled-select"}) %&gt;&lt;br&gt;
    &lt;/span&gt;
  
    &lt;br&gt;&lt;label&gt;Number of Guest:&lt;/label&gt;&lt;p &amp;nbsp;&gt;&lt;/p&gt;
    &lt;span class="table"&gt;
      &lt;%= f.select(:guest_size, options_for_select(1..6), {:class =&gt; "styled-select"}) %&gt;&lt;p &amp;nbsp;&gt;&lt;br&gt;
    &lt;/span&gt;
  
    &lt;label&gt;Reservation date &lt;/label&gt;&lt;p &amp;nbsp;&gt;      
    &lt;div&gt;
      &lt;span class="datetime"&gt;
        &lt;%= f.date_select :requested_date, order: [:month, :day, :year],:class =&gt; "styled-select"%&gt;&lt;br&gt;&lt;br&gt;
      &lt;/span&gt;
    &lt;/div&gt;
  
    &lt;label&gt;Reservation Time&lt;/label&gt;&lt;p &amp;nbsp;&gt;        
    &lt;div&gt;
      &lt;span class="datetime"&gt;
        &lt;%= f.time_select :requested_time,  ampm: true , minute_step: 30, start_hour: 8, end_hour: 22, :class =&gt; "styled-select" %&gt;
      &lt;/span&gt;
    &lt;/div&gt;&lt;br&gt;&lt;br&gt; &lt;!-- ,{ampm: true} --&gt;
  
    &lt;label&gt;Reservation fee:&lt;/label&gt;&lt;p &amp;nbsp;&gt;&lt;/p&gt;
    &lt;div&gt;
      &lt;span class="datetime"&gt;
      &lt;%= f.select :payment_id, Payment.all.map{ |j| [j.pay_reservation, j.id] }, :class =&gt; "styled-select"%&gt;&lt;br&gt;&lt;br&gt;
      &lt;/span&gt;
    &lt;/div&gt;
    &lt;div class="field"&gt;   
      &lt;br&gt;&lt;div class="actions"&gt;&lt;%= f.submit "Confirm Reservation", class: "btn-style" %&gt;&lt;/div&gt;&lt;br&gt;  
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>