Skip to content

Instantly share code, notes, and snippets.

@stephepush
Created July 30, 2020 19:37
Show Gist options
  • Save stephepush/a96f2ab401109b6276dcdb4b53a55c7f to your computer and use it in GitHub Desktop.
Save stephepush/a96f2ab401109b6276dcdb4b53a55c7f to your computer and use it in GitHub Desktop.
Car dealer Backend Files
#CarItem model
class CarItem < ApplicationRecord
belongs_to :model_info
end
class CarItemsController < ApplicationController
def index
@CarItem = CarItem.all
render json: @CarItem
end
end
#ModelInfo model
class ModelInfo < ApplicationRecord
has_many :car_items
end
class ModelInfosController < ApplicationController
def index
#get all the listings from the database
@ModelInfo = ModelInfo.all
render json: @ModelInfo
end
end
Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
resources :model_infos, only: [:index]
resources :car_items, only: [:index, :show]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment