Images not being served from assets - ruby-on-rails

I have just performed a fresh install of Rails 3.2. The default "Welcome aboard" page was served fine when testing with built in webserver, however when I switched to Passenger together with Apache the Rails logo stopped showing up.
The image is located in /myapp/app/assets/images/rails.png and is called from document as assets/rails.png. This return 404.
I have set 755 permission on /myapp/app/assets folder and have Allow from all in my virtual host configuration.
Any help would be appreciated.

Check out in your config/production.rb that you have
config.serve_static_assets = true
and serving static assets is also enabled in your Apache and site configuration.

Related

Loading webpacker assets in production

I'm trying to deploy to production (on a local machine) a Rails 5.2 app which uses webpacker for assets managemnet (I have totally replaced the assets pipeline).
Everything seems ok: as part of my deployment process I run the webpacker:compile task and both JS and CSS are compiled in the public/packs folder.
However, the assets aren't loaded from the app even if they are correctly linked.
Am I missing anything here?
I have tried to load via browser other files in the /public folder (i.e. robots.txt) but they are not availble neither. I get "The page you were looking for doesn't exist." error message.
In production by default rails expects to be behind a reverse proxy server like nginx that will serve all static files from public more efficiently.
Also for low loads the built-in file server can be enabled as a quick-fix, in production.rb:
config.public_file_server.enabled = true

rails 4.2 capistrano 3 Ubuntu nginx puma, getting routing error/no assets shows up

After following this tutorial, I tried was able to set up a rails application on an ec2 Ubuntu instance, running nginx web server and puma app server, deployed with capistrano 3. However, none of my assets are showing up, and I'm getting routing errors for basic functions of the Devise gem such as logging out. The chrome dev tool console shows 404 errors for the compiled application.css and application.js files.
I think the assets are there because if I ssh into the instance and go to the folder where my app is, I can see a bunch of files under public/assets. Also, if I check the capistrano logs, I can find the line bundle exec rake assets:precompile, and the status for that is successful. I tried things like going into the production.rb file and changing config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? to config.serve_static_files = true
but still no assets. I think the biggest suspect is that there is some sort of routing error, because I don't really understand how web servers, app servers, and aws instances interact with each other. Could anyone point me in the right direction on debugging this? If you need to see a specific config file please comment below.
Ok it turns out all I had to do is copy the secrets.yml from the local repo for my app to the shared folder that is in [my_app_name]/shared/config. So my app didn't know where to look for the secret key base.
Although I'm still confused on why not having the secret.yml would prevent assets from served...

rails 4 static assets not being served even after setting config.serve_static_assets = true

I've created a rails 4, ruby 2 app. In development mode, it's working fine. But if I start the server in production mode, it fails to serve all the images and javascript files.
I've set config.serve_static_assets = true in my production.rb. Still, I get a 404 error. What could be the possible reason?
Any help would be highly appreciated.
When running the server in production mode the system expects that the assets will be precompiled and available in the public folder.
To test this you should run the precompile task. You'll see that a folder called assets is created inside of the public folder, and inside this all your assets will be created.
WARNING: You should delete this folder when you are done testing, and clear the asset cache in the /tmp folder before going back to dev mode. Failing to do this will result in the app serving the precompiled assets in dev mode and you won't see any changes that you make.

How to serve a non static files in rails

I have an action, that generates a PDF files and save it in the /public/output.pdf.
When I set
config.serve_static_assets = false
this file can't be found.
What's wrong ?
From the documentation:
"config.serve_static_assets configures Rails itself to serve static
assets. Defaults to true, but in the production environment is turned
off as the server software (e.g. Nginx or Apache) used to run the
application should serve static assets instead. Unlike the default
setting set this to true when running (absolutely not recommended!) or
testing your app in production mode using WEBrick. Otherwise you won´t
be able use page caching and requests for files that exist regularly
under the public directory will anyway hit your Rails app."
Which means that if you set that to false Rails will not serve any assets from your public folder as it is assumed that a front-end web server (apache/nginx) will handle it. This lessons the load on Rails as the front-end server is much, much more efficient at serving files directly.
After testing, I came to this conclusion:
1) when using the command
rails s -e production
Rails will only serve the statics files. Any other file created after you compile your assets will not be found.
To handle this, you need to execute your application under a web server like Apache, Nginx or other. These web servers will serve this files for you.
This looks to be obvious, but not for a beginner.

Changes made in rails app /public directory not reflecting on server

I have an replica of the live app that is deployed on the server. I have made some changes: like inserted 2 css and js files in /public directory that serves my assets and included in the views where they are required .It is working fine on my Local machine but when I pushed the changes to the server it is not reflecting over there. I am Using Nginx and I have tried restarting it as well but it didn't help either.
As I am new to NGINX and the App is deployed on a centos I dont know how it works.
I already have precompiled assets, So I don't know how to make it run. I have tried
Clearing the cache from tmp directory but didn't work.
I have set my
config.serve_static_assets = false
in my production.rb and tried restarting but didn't work either
Any help ??
Your views are cached in webserver workers. Have you restarted your web workers?

Resources