我是 ruby on rails 的新手,但不是编程的新手。我有一个问题要查询。我也知道 restaurants 拼错了
class ResturantsController < ApplicationController
before_action :set_resturant, only: %i[ show edit update destroy ]
# GET /resturants or /resturants.json
def index
@resturants = Resturant.all.order("created_at desc")
end
# GET /resturants/1 or /resturants/1.json
def show
@food_items = FoodItem.find(resturant = Resturant.name)
end
为什么我可以获得特定的 GET 以按名称获取餐厅,例如/resturants/McDonalds
我还想将@food_items = FoodItem.find(resturant = Resturant.name) 写成 SELECT * from food_Items WHERE (restaurant: restaurant.name)
最佳答案
通过名称获取餐厅
@resturants = Resturant.find_by_name("restuarant_name")
获取食品
@food_items = FoodItem.where(resturant: "restuarant_name")
https://stackoverflow.com/questions/72451434/
相关文章:
javascript - 使用 react-chartjs-2 创建对折线图的引用
javascript - javascript(ASP.Net)中的计时器倒计时
javascript - 我如何构建一个用一组新按钮回复的不和谐按钮
python - 直接查询 Sqlalchemy-utils EncrytedType 作为 SQL
ios - 如何在 App Store Connect 中启用 "Access to Cloud M
javascript - React-TypeScript : Expected 0 argumen
javascript - 未捕获的类型错误 : Failed to resolve module s