app/controllers/services_controller.rb
# find_by_id wont error out and is just nil if it cant find it
find_by_id wont error out and is just nil if it cant find it
find_by_id wont error out and is just nil if it cant find it
def index
    if params[:ai_id]
      @ai = Ai.find_by(id: params[:ai_id])
      if @ai
        @services = @ai.services.order_by_price.search(params[:search])
      else
        redirect_to ais_path, alert:"AI not found"
      end
    else
      @services = Service.all.order_by_price.search(params[:search])
    end
  end
def index if params [ :ai_id ] @ai = Ai . find_by ( id : params [ :ai_id ] ) if @ai @services = @ai . services . order_by_price . search ( params [ :search ] ) else redirect_to ais_path , alert : "AI not found" end else @services = Service . all . order_by_price . search ( params [ :search ] ) end end
find_by_id wont error out and is just nil if it cant find it
find_by_id wont error out and is just nil if it cant find it
#binding.pry #@ai = Ai.find_by(id: 12) #binding.pry #byebug