B05999
B05999

Reputation: 53

Ruby on rails query don't know how to write it

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
  1. the there any why where I can get a specific GET to get restaurant by name so /resturants/McDonalds for example

  2. also I want @food_items = FoodItem.find(resturant = Resturant.name) to be written as SELECT * from food_Items WHERE (restaurant: restaurant.name)

Upvotes: 1

Views: 44

Answers (1)

Shaher Shamroukh
Shaher Shamroukh

Reputation: 367

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")

Upvotes: 2

Related Questions