0
我有餐馆,用户可以预订。对于预订,我将我的时间属性设置为integer
。然后,我使用助手来显示时间选择(单选按钮),例如14点到2点。ActiveSupport :: TimeWithZone与12次失败的比较
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
预约时间选项显示餐厅页:
<%= form_for([@restaurant, @reservation], :html => {:class => 'reserve-form'}) do |f| %>
<div class="times">
<% @restaurant.hours_open.each do |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>
现在,当预订完成后,我重定向到用户配置文件,以显示该保留。在开发方面一切正常,但在部署到heroku后,我得到错误“我们很抱歉,但出错了。”当进行预订时,我认为它与预订时间显示在下面显示的用户页面上有关。
当我检查Heroku的记录是这样的错误:
ActionView::Template::Error (comparison of ActiveSupport::TimeWithZone with 12 failed):
<% @user.reservations.each do |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'
该数据类型不是时间,因为我已将它设置为整数。这是我的模式:t.integer“time” – Ezde
以及提供的代码,我看不出任何问题......但为什么不使用时间数据类型? – jazzytomato
好的会做..感谢 – Ezde