Favicon not found in production mode - ruby-on-rails

Firefox does not find the favicon of my Rails 3.1 app in production mode. Running in development mode, it works.
I browse to the URL localhost:4000/favicon_standing.ico for both modes.
The favicon is located in my public folder of my app. I do not use the asset pipeline for it.
I start the server using rails s -p 4000 -e production and rails s -p 4000, respectively, using WEBrick.
Why does is for in development mode, but not in production mode?

I'd try changing the name of your file to 'favicon.ico' and see if that helps. While its not required, its the default naming convention and if you're using another name, you have to add some html to your head:
<link rel="shortcut icon" href="http://www.my-domain.com/myfavicon.ico" type="image/x-icon" />
Here's what some googling shows:
http://www.make-a-favicon.com/favicon_FAQs.htm#Are_all_favicon_files_named_favicon.ico

there is a helper for this
<head>
...
<%= favicon_link_tag %>
<!-- you can skip the name of file if it is favicon.ico -->
...
</head>
all you need is to place your favicon to assets/images/ folder and recompile assets

Related

Rails 7 - picking up assets automatically in dev doesn't work

For some unknown reason Rails 7 (development environment) doesn't pick up changes in application.js automatically when I hit F5 in the browser. The location application.js is default. I'm using pretty much default setup.
When I run the server, it picks up javascript from some cached version. I need to explicitly rails assets:precompile to make it work.
Importmap looks standard:
# Pin npm packages by running ./bin/importmap
pin "application", preload: true
...
And layout file seems pretty standard as well:
<!DOCTYPE html>
<html>
<head>
<title>Whatever</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="<%= image_path('favicon.svg') %>">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
</head>
...
I tried to set config.importmap.sweep_cache = true in my development.rb (as per importmap docs), but it seems there is no effect.
At this point I'm pretty desperate and can't understand why do I need to rails assets:precompile on my development environment.
Also, I'm not running my app on "localhost" domain, it's on something like dev.server-somewhere.com (so it's accessible from anywhere) with SSH redirects, similar to ngrok. Not sure if it's the cause of a problem.
For clarification: I'm looking for no LIVE refresh feature, just the standard approach with F5 page refresh would work.
I have same problem, simply use: rails assets:clobber to clear all precompiled assets. After that the hot reloading will start working again.
if existing precompiled JS assets exist in public/assets/ rails gives them a priority even in development mode (and even when, for example, esbuild or tsc-watch is otherwise working to transpile your source files into app/assets/buils/, which is unrelated to Sprocket hanging onto its old cache)
Normally, assets are "precompiled" only in production/deployed environments. That means that by default there shouldn't be a folder at public/assets/ while you develop (Sprockets compiles assets on-the-fly for you in development mode).
If you accidentally have run rails assets:precompile in development, you'll have an extra folder here (public/assets/) which does not get checked in to your repository.
But if it does exist, then its existence overrides Sprocket's development mode setting to recompile on every pageload, forcing your browser to load the already compiled (and stale) asset from public/assets/...
(Ironically, running rails assets:precompile or rake assets:precompile, while it does force a one-time recompile and seemingly gives you your latest JS compile, doing this in development is typically what causes the problem of Sprockets getting stuck in the first place)
Next, force Sprockets to both delete the public/assets/ folder and then bust the thumbprint cache using:
rails assets:clobber
(alternatively, run rails assets:clean and then touch tmp/restart.txt)
To debug further, set assets.debug = true in your environment file.
I have faced this issue today and I replaced the sprockets with the propshaft. Then it worked! You might look at the upgrade guide.
I was facing the same issue today and simply reverted back to Sprockets and everything worked out of the box after installing the gem. It seems that Sprockets is now optional in Rails 7. I don't know if Sprockets can be combined with Import Maps, though.

How to set a default webapp in jetty Docker

Is there a way to set in the Dockerfile of jetty the default webapp?
The doc says, you can rename you webapp.war as root.war, but if don't want to do that, is there a way to specify the webapp as you default (and only) webapp.
Do I have to modify the Dockerfile or can I specify in the webapp (context.xml)
Thanks, Rajesh
I am guessing you want to access webapp.war by using <hostname:port> with out the web app name..
you can do redirection by using root/index.html which redirects to your web app..
content of index.html would be
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<META HTTP-EQUIV="Refresh" CONTENT="0; URL=/<your Web app name>/"/>
</head>
<body>
</body>
I think you can create a jetty config file under project/WEB-INF, you can also see it http://www.eclipse.org/jetty/documentation/current/configuring-specific-webapp-deployment.html#deployable-descriptor-file

Converting Ember Rails app to phonegap

I have just start using both Ember and Phonegap and I am using the Ruby on Rails Ember-Rails gem as wanted to use Rails to do the asset pre-compilation. I can use rails s to run the Ember app and all works fine. To get into a phonegap app, I am doing a rake assets:precompile command, then copying the fingerprinted css and js files to an assets directory and modifying the index/html file to pick them up as follows:
<!DOCTYPE html>
<html>
<head>
<title>MahimanagerPhoneApp</title>
<link rel="stylesheet" media="all" href="./assets/application-f82ab2dfef6aa5b0589d092d8949fc1e6126d774e74d5a024c1407a7082732f6.css"/>
<script src="./assets/application-0df5442d7ea56c8d2a38022448c2c9b57397f561885306bbdfff8db7962547c3.js"></script>
</head>
<body>
<div id="ember-app"></div>
</body>
</html>
I then copy the index.html and the assets into a phonegap app directory. When I use the phonegap cli to build the app and launch it on on emulator it comes up with "Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)". I have tried the various solutions in this post :Application Error - The connection to the server was unsuccessful. (file:///android_asset/www/index.html)
but none resolved my problem. When I open the index.html in a browser I get Uncaught UnrecognizedURLError: /home/paul/Documents/testapp/www/index.html which is coming from somewhere within the ember.js file but I assume this is only because it was loaded from the file system rather than severed from a host.
I have looked into the phonegap-rails gem too, but it looks like the commands it expects to run in phonegap are from an older version and no longer work.
I am not really sure where to go from here, and maybe its just not a good idea to try and do this from rails?
UPDATE:
I gave up on trying to get this to work. I have instead gone with the ember-cli-cordova option (https://github.com/poetic/ember-cli-cordova). Which had a few minor stumbling blocks that were all easily solved and now I am up and running....
If you change the locationType in your environment.js file to 'hash', rather than 'auto', you will solve this issue.
The issue is that phonegap access your app at a url such as file:///android_assets/www/index.html
ember tries to resolve the index.html as a route when the locationType is set to auto.

Assets starting from the root of the server (rails 4)

When I'm using local Webrick server on my local machine everything is OK, but after uploading my project to remote server (unicorn + nginx) i had bug with assets path. Now its starting from the root of the server:
<link href="/var/www/rails/demo/assets/application-2432a9098f54da0c4d34883512814c4b.css" media="all" rel="stylesheet" />
My app is located in /var/www/rails/demo/
What I'm doing wrong?
It probably has the same problem on your local machine, only it works because this path is available locally.

How to run .erb files in browser with a customized directory?

How can I run .erb files in the browser? It is not in the Rails framework so I can't run in terminal the "rails server" command.
It is like a customized directory with .erb files.
This is the directory structure:
Do I need a webserver to run it like WEBrick for me to see it in localhost? How can I access it?
Thanks.
Are you using a different Ruby framework or need to access server data? If not, you can generate HTML from erb with the command line, then simply open the HTML:
<% # page.erb %>
<html>
<head>
<title>My erb</title>
</head>
<body>
<h1>it is: <%= Time.now %></h1>
</body>
</html>
To compile and open from the command line:
$ erb page.erb > page.html
$ open page.html

Resources