• 0

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /var/www/html/cnasolution/application/views/question.php
Line: 191
Function: _error_handler

File: /var/www/html/cnasolution/application/controllers/Questions.php
Line: 419
Function: view

File: /var/www/html/cnasolution/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Rails 6 App links not working until refresh

I tried to follow this tutorial by GoRails to add EasyAutoComplete to my Rails app: https://www.youtube.com/watch?v=ibxlNN73UTY

Although the search bar functions as the GoRails guy demonstrates, I keep seeing this page whenever I click on any link: error page

If I refresh this page, then it takes me to the user sign in page that I originally clicked on. I don't notice anything out of the ordinary in my Rails server console throughout this process.

I added the css files and the js files for EasyAutoComplete to my Assets pipeline, because I was having a hard time using webpacker correctly.

For jquery, I followed this article to install it: https://www.botreetechnologies.com/blog/introducing-jquery-in-rails-6-using-webpacker and I used this video as reference as well: https://www.youtube.com/watch?v=bn9arlhfaXc

My Gemfile looks like:

source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" }  ruby '2.6.2'  # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 6.0.0.rc2' # Use postgresql as the database for Active Record gem 'pg', '>= 0.18', '< 2.0' # Use Puma as the app server gem 'puma', '~> 3.11' # Use SCSS for stylesheets gem 'sass-rails', '~> 5' # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker gem 'webpacker', '~> 4.0' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.7' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 4.0' # Use Active Model has_secure_password # gem 'bcrypt', '~> 3.1.7'  # Use Active Storage variant # gem 'image_processing', '~> 1.2'  # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.4.2', require: false  group :development, :test do   # Call 'byebug' anywhere in the code to stop execution and get a debugger console   gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] end  group :development do   # Access an interactive console on exception pages or by calling 'console' anywhere in the code.   gem 'web-console', '>= 3.3.0'   gem 'listen', '>= 3.0.5', '< 3.2'   # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring   gem 'spring'   gem 'spring-watcher-listen', '~> 2.0.0' end  group :test do   # Adds support for Capybara system testing and selenium driver   gem 'capybara', '>= 2.15'   gem 'selenium-webdriver'   # Easy installation and use of web drivers to run system tests with browsers   gem 'webdrivers' end  # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] gem 'redis' gem 'braintree' gem 'bcrypt' gem 'foreman' gem 'rails-controller-testing' gem 'faker' gem 'pagy' gem 'figaro' gem 'gon' gem 'modernizr-rails' gem 'stripe-rails' # thirdparty authentications gem 'omniauth-google-oauth2' gem 'omniauth-facebook' gem 'omniauth-twitter' gem 'activerecord-session_store' # for front end gem 'react-rails' gem 'bootstrap' gem 'sprockets-rails' gem 'jquery-rails' # catches test emails gem 'mailcatcher' gem 'devise' # admin panel gem 'rails_admin'  # active storage variant gem 'mini_magick', '~> 4.8' gem 'rack', '~> 2.0.8' gem 'ransack' 

My search.js looks like:

document.addEventListener('turbolinks:load', function () {   $input = $("[data-behavior='autocomplete']")    var options = {     getValue: 'name',     url: function (phrase) {       return '/search.json?q=' + phrase     },     categories: [       {         listLocation: 'products',         header: 'Products'       }     ],     list: {       onChooseEvent: function () {         var url = $input.getSelectedItemData().url         $input.val('')         Turbolinks.visit(url)       }     }   }    $input.easyAutocomplete(options) }) 

My application.js in app/javascript/packs looks like:

require('@rails/ujs').start() require('turbolinks').start() require('@rails/activestorage').start() require('channels') require('jquery')  //= require jquery //= require popper //= require bootstrap-sprockets //= require jquery.easy-autocomplete 

Any help would be greatly appreciated!

Download script demo [LINK]
Download script demo [LINK 2] Download script demo [LINK 2]