When Ruby on Rails does not render CSS and Images look disproportionate on Linux Ubuntu Destro (Windows Subsystem) try the following below:
problem: If you're developing Ruby on Rails on Windows Linux Sub System, Windows might block port 3012 or you might get an error like below, this will force you to start Rails Server on a different port that might break the Ruby Assets Pipeline from getting requested since the Asset_Host might be hardcoded to request on a different port.
/vendor/bundle/ruby/2.5.0/gems/puma-3.12.1/lib/puma/binder.rb:273:in `initialize': Permission denied - bind(2) for "0.0.0.0" port 3014 (Errno::EACCES)
Write an Article
- Make sure no other apps like VS Code or Git Client are using the same [Web App directory] where the website is located because one process can lock the other.
- Before running any commands in your project directory using your favourite Console App (e.g. Powershell, CMD, Bash etc), Open up Development Tools and navigate to Network Tab. On Network tab click "All" to see all static files being requested from the Server and examine those that show in "Red" or says "Fail". Then click on one of the failed files and examine the "Header" section of the section opened. This is an important step, verify that the port that shows next to localhost:(port number) matches with the port number you started Rails Server on. If not, that is where the problem is. To Fix this, Stop the Rails Server by pressing Ctrl + C (If pressing Ctrl + C) does not stop the Rails Server then kill Puma Process with this command (pkill -9 -f puma) make sure you are in a website directory for these commands to work.
- After the Rails Server has been stopped, Start the Rails Server on a port you saw in the Development Tools e.g localhost:3012 by typing this command: rails s -p 3012
- Your problem should be solved. If not, then proceed to the rest of the list.
- Open up Bash or your favorite Console App and navigate to the folder where the website is located and run:
- sudo bundle update
-After the installation or updates are installed try to run the Rails Server by typing: Rails s which starts the server on port 3000
- Sometimes starting the server on default port does not work, in this case, proceed to number 3.
- If number 2 did not work, try starting the Rails Server on a different port like so: rails s -p 3001
- If number 3 does not work, observe the logs and pinpoint what the error seems to be and start troubleshooting from there.
Please Login to see the rest of the answer
Answer: Another Option that Works]
6. Go to your project folder, if you are using VS Code IDE and Search for "asset_host"
- There is a big chance that the URL for requesting Assets is hard-coded under development.rb found in: config = environments = development.rb
- Change the config.action_controller.asset_host = "http://localhost:PortNumberYouAreRunningRailsAppOn"