I am new to ruby on rails but not programming. I have a question for queries. Also I know restaurants is spelled wrong
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
the there any why where I can get a specific GET to get restaurant by name so /resturants/McDonalds for example
also I want @food_items = FoodItem.find(resturant = Resturant.name) to be written as SELECT * from food_Items WHERE (restaurant: restaurant.name)
CodePudding user response:
To get the restaurant by name
@resturants = Resturant.find_by_name("restuarant_name")
To get the food items
@food_items = FoodItem.where(resturant: "restuarant_name")