class BrandsController < ApplicationController before_action :find_brand, only: [:show, :edit, :update, :destroy] def index @brands = Brand.all.order("created_at DESC") end def show end def new @brand = Brand.new end def create @brand = Brand.new(brand_params) if @brand.save redirect_to root_path else render 'new' end end def edit end def update if @brand.update(brand_params) redirect_to brand_path(@brand) else render 'edit' end end def destroy @brand.destroy redirect_to root_path end private def brand_params params.require(:brand).permit(:name) end def find_brand @brand = Brand.find(params[:id]) end end