Loading production assets from a user's local host instead of an Ubuntu server in Rails

After successfully deploying my Rails application to an Ubuntu 16.04 Droplet, I encountered a problem with the CSS when running the server locally. The website could be accessed at myappname.com through the browser as long as the rails server was active, but once it was shut down, the CSS would fail.

Furthermore, the CSS consistently failed for anyone accessing the site from a device other than my local computer.

The root cause of this issue is due to me mistakenly hard coding the site to attempt to retrieve files from the local computer of whoever visits the site instead of the actual server. The error message highlights this problem:

http://localhost:3000/assets/jquery-ui/accordion.self-ahsdjhkjads98ha98shd8ha98hds98hadskjhfo4h8fw9hhw398hhiuh9sd8h8hs89fdhj.css?body=1 Failed to load resource: net::ERR_CONNECTION_REFUSED

Since "localhost" is mentioned in the URL, every visitor will try to load the page using something on their own local computer. In reality, it's my computer listening on port 3000 in this scenario, so I must adjust how the site code fetches CSS assets from itself rather than localhost.

In

config/environments/production.rb
, I made the following change:

config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?

to:

config.serve_static_files = true

Subsequently, on my Ubuntu server within the production environment, I executed

bundle exec rake assets:precompile
, restarted the server with sudo service apache2 restart, yet the issue persisted. Any assistance provided would be greatly valued.

Answer №1

One potential solution is to set the variable config.asset_host within the file config/application.rb to match your domain. However, it appears that the issue may lie in a misconfiguration of your reverse proxy.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Potential Issue with CSS General Sibling Selector

It seems like I have encountered a potential bug with the General Sibling Selector. When I use p ~ div, the selector does not work as expected. However, when I replace p with the specific class name text_paragraph, it works fine. You can view my code and f ...

Having trouble with the menu toggle button on Bootstrap 4?

When using Bootstrap 4, the breadcrumb button may not function properly when the header becomes responsive. I have ensured that Bootstrap 4 CSS and JS are included in the project. Please assist me in resolving this issue. Code: .navbar { height:100 ...

Fuzzy text upon scrolling in Internet Explorer version 6

Having a problem with text in Internet Explorer. When the page initially loads, the text appears clean and sharp. However, when I double-click on some white space of the page, the text becomes distorted as shown in the following image: Click here for alt ...

Styling web pages with HTML and CSS directly from a MySQL

I'm facing a challenge in crafting a solution for a intricate issue. My project involves building a website that generates HTML templates containing both CSS and HTML files. Users will have the ability to create multiple templates/sites. In an effort ...

Troubles with CSS drop down alignment in Internet Explorer 7

I've been racking my brain all morning trying to solve this issue. My current project involves creating a website for a client, and I'm having trouble getting the dropdown menu to position correctly in IE7. It's working fine in all other br ...

When the window is resized, the text and images become jumbled and distorted

As a beginner in CSS, I am encountering an issue where the text and images on my website get distorted when I resize the window. How can I resolve this? HTML <img src="images\titles_03.jpg" class="tt1" > <img src="images\titles_05.jpg ...

Unable to Change Navbar Color

Presented here is the code snippet for the navbar located in app/assets/views/elements: <nav class="navbar navbar-default" role="navigation"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> ...

section element is not receiving styles from the specified class

Whenever I want to ensure that a class is only used on specific elements, I usually prefix it with the element name. For example, using div.className limits the className styling to just div elements. However, when I tried the same approach with a section ...

How come Font Awesome icons aren't appearing in my link?

Is my question strange? I've noticed a peculiar behavior when using fontawesome. Normally, it displays correctly, and I have already referred to the documentation, but none of the solutions I found here seem to solve my issue. Sources I have tried: ...

Issues with special characters in @font-face rules

For some reason, I'm encountering issues with the CSS3 property @font-face in certain browsers when trying to use my own fonts. Chrome, Safari, and IE10 work fine, but other browsers present several problems: The code I used looks like this: (fonts G ...

Steps to limit access to a dockerized MongoDB instance from other containers on the same server while also preventing public access to port 27017

I am currently utilizing Orion Context Broker within a docker container and I need to establish a connection with MongoDB, which is housed in its own docker container. However, it is imperative that I block all incoming traffic to port 27017 from external ...

Button Hover Effect: Transition with Style

I am trying to implement a one-second transition from the default color scheme to the hover color for a Button element in Material UI. I am using the transitions.create(props, options) method as described in this article: https://medium.com/@octaviocoria/c ...

Take off the wrapping from the package

I need help with my code on how to remove the wrapper span tag without removing the text. <ul> <li> <a href="#"> </a> <ul> <li> <a href="#"> ...

Gradient that runs in a straight line from opposite ends

Is there a way to apply linear gradients from both the top and bottom to create smoother lines when text is scrolled? I was able to achieve a linear gradient at the bottom using this code: <div className="vsebina" style={{WebkitMaskImage:&apo ...

Tips for ensuring a static html element remains visible at the bottom of the screen even when the soft keyboard is opened in iOS Safari

Within a webpage, there is an input field and a fixed div positioned at the bottom of the window using CSS properties such as position:fixed; and bottom:0;. To better illustrate this setup, I have created a Codepen demo which can be viewed here: https://c ...

Animating ng-switch transitions within a div element

Utilizing bootstrap 3 panel along with ng-switch for a sliding animation: Check out the Plunker here I am facing an issue where the animation extends past the borders of the panel instead of staying within it. How can I fix this in my Plunker? The desire ...

Inline display with automatic margin

I am seeking guidance from someone with more experience to help identify the source of this margin. Your assistance is greatly appreciated! https://i.stack.imgur.com/46k7k.png Below is the CSS code in question: .logo-icon { background-image: url(&ap ...

Clear HTML

Is there a way to create a 'div' element in an HTML document and adjust the background transparency using CSS or Javascript/JQuery in order to achieve a look similar to Simple Calendar Widget or Glass Widgets from Android? I have tried using the ...

Creating a dynamic CSS hover animation for an input element with jQuery to ensure compatibility with Microsoft Edge

I am facing an issue where I have a row of six to nine switches with the <input type="checkbox"> element, and each switch animates when hovered over. In this animation, the knob slides down, and both the knob and track fill with colors or gradients. ...

Modify the hue of a background image in PNG format

I'm currently using a CSS selector on my site to display an icon for external links on any href that isn't directing to my own domain. Here's the code snippet I'm referring to: a[class=" external-link"]::after { content: url(data:im ...