ruby on rails - comparison of ActiveSupport::TimeWithZone with 12 failed -


i have restaurants user can make reservations. reservations, set time attribute integer. used helper display time selection(radio button) such 14 2:00pm.

  def new_time(h)     if h > 12       (h-12).to_s + ":00 pm"     elsif h == 12       h.to_s + ":00 pm"     else       h.to_s + ":00 am"     end   end 

reservation time options displayed on restaurant page:

<%= form_for([@restaurant, @reservation], :html => {:class => 'reserve-form'}) |f| %>   <div class="times">     <% @restaurant.hours_open.each |h| %>       <%= f.radio_button :time, h %>       <%= f.label "time_#{h}", new_time(h), class: "reserve" %>     <% end %>   </div>   <div class="align">   <%= f.label :party_size,'please enter party size' %>   <%= f.text_field :party_size %>   </div>   <div class="align">   <%= f.submit %>   </div> 

now when reservation done, redirect user profile display reservation. works fine on development side after deploying heroku, error "we're sorry, went wrong." when making reservation , think has reservation time displayed on user page shown below.

when check heroku logs error:

actionview::template::error (comparison of activesupport::timewithzone 12 failed):          <% @user.reservations.each |reservation| %>         <div class="user-reservation align">         <p>restaurant: <%= reservation.restaurant.name %></p>         <p>reserved time: <%= new_time(reservation.time) %></p>         <p>party size: <%= reservation.party_size %></p>         <p>added on: <%= reservation.created_at.strftime("%b %d, %y") %></p>     app/helpers/application_helper.rb:3:in `>'     app/helpers/application_helper.rb:3:in `new_time'     app/views/users/show.html.erb:19:in `block in _app_views_users_show_html_erb__1649677434053595894_70057403913200'     app/views/users/show.html.erb:16:in `_app_views_users_show_html_erb__1649677434053595894_70057403913200' 

you comparing attribute reservation.time activesupport::timewithzone integer.

if datatype time, why don't use format strftime ?

<p>reserved time: <%= reservation.time.strftime("%i:%m%p") %></p>  

Comments