ruby-on-rails - 在 Rails 中显示查询结果时遇到问题
问题描述
我正在 Rails 中创建航班预订程序,但在显示符合条件的 Rails 航班的航班信息时遇到问题。用户可以选择往返机场、乘客和航班日期。如果航班存在,它会显示信息。但是我的航班没有显示。
显示航班的 index.html 表单
<p>
<% unless @eligible_flights.empty? %>
<% @eligible_flights.each do |f| %>
<%= f.start_airport_id %>
<% end %>
<% else %>
<%= "No Flights Found" %>
<% end %>
</p>
飞行控制器查看
def index
@flights = Flight.all
@eligible_flights = Flight.where("start_airport_id = ? AND end_airport_id = ? AND departure_time = ?",
params[:start_airport],
params[:end_airport],
params[:departure_time])
end
解决方案
我最好的猜测是日期比较无法正常工作,您应该尝试使用 Rails 方式实现您的查询。
@eligible_flights = Flight
.where(start_airport_id: params[:start_airport])
.where(end_airport_id: params[:end_airport])
.where(departure_time: params[:departure_time])
推荐阅读
- javascript - 页面加载时将 div/页面内容变灰
- c - 在 C 中以 IEEE 标准打印浮点数(十六进制)
- google-sheets - 如何根据日期计算记录并将它们放在每月表格中
- firebase - 使用 apollo graphql 服务器为 next.js 托管的 firebase 云函数
- flutter - 添加 integration_test 包时应用程序构建崩溃
- html - 我怎样才能有分屏布局
- create-react-app - Craco - 无法解决依赖错误
- excel - 禁用 Windows 中特定应用程序的可访问性
- sql - 如何反转错误建模的 1:1 关系?
- vue.js - Vue.js 模板上的 PhpStorm 未解析变量