gpt4 book ai didi

ruby-on-rails - Ruby on rails query 不知道怎么写

转载 作者:行者123 更新时间:2023-12-05 04:28:59 26 4
gpt4 key购买 nike

我是 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
  1. 为什么我可以获得特定的 GET 以按名称获取餐厅,例如/resturants/McDonalds

  2. 我还想将@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")

关于ruby-on-rails - Ruby on rails query 不知道怎么写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72451434/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com