我是 ruby?? on rails 的新手,但不是編程新手。我有一個疑問。我也知道餐館拼寫錯誤
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)
uj5u.com熱心網友回復:
按名稱獲取餐廳
@resturants = Resturant.find_by_name("restuarant_name")
獲取食物
@food_items = FoodItem.where(resturant: "restuarant_name")
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/483820.html
