Ruby 关于 rails 查询不知道怎么写
Ruby on rails query don't know how to write it
我是 ruby 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 * 来自 food_Items WHERE(餐厅:restaurant.name)
通过名称获取餐厅
@resturants = Resturant.find_by_name("restuarant_name")
获取食品
@food_items = FoodItem.where(resturant: "restuarant_name")
我是 ruby 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 * 来自 food_Items WHERE(餐厅:restaurant.name)
通过名称获取餐厅
@resturants = Resturant.find_by_name("restuarant_name")
获取食品
@food_items = FoodItem.where(resturant: "restuarant_name")