I had this similar error above, after generating my controller for home with index using the command below
rails g controller home index
and when I tried to access my localhost:3000/home/index
I get an error in the image above. it was frustrating as a newbie to rails. I searched for solutions on StackOverflow, Google searches to blog post, and lots more, I could not seems to get a one-stop solution, but finally, I tried something and it work.
I will put down how I fixed it and throw away all the hustle for you. below are the commands you need to run on your terminal to fix this error. This solution was implemented on Linux( Kali Linux)
Step 1: You need to install the last stable version of Nodejs. for me my last stable version was version 16 and I was using version 17, which was not stable at the time of writing this article.
- Installation of Nodejs stable version for version 16 (run the following commands)
nvm install 16
nvm use 16.14.2
- Installation of Nodejs stable version for version 16 (run the following commands)
Step 2: I had to install yarn globally as well ( run the following command)
npm install yarn
Step 3: I installed Webpacker again
bundle exec rails webpacker:install
Step 4: I was not too confident with step 3 ๐, so I ran the command below
yarn add @rails/webpacker
Step 5: Final step, I ran the command below
rake assets:precompile
The command on step 5, the config below was added to the gemfile.lock
PLATFORMS x86_64-darwin-21 //this existed x86_64-linux //this was added
I hope this helps, If it helped please leave a comment so other people know it works and tries it out. Also if you used another approach that worked, please leave a comment too.