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

Time:06-01

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)

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

  • Related