Dokku Rails application missing static assets with 404 error - ruby-on-rails

I deployed a rails application with Dokku. Everything went fine except that all my assets including images returns a 404 error.
I really don't know how to debug this.

For dokku it is simple to add:
dokku config:set <your-app> RAILS_SERVE_STATIC_FILES=true

I had exact same issue and adding the following gem solved it:
gem 'rails_12factor', group: :production
That's the official way of dealing with that issue on Heroku for Rails 3 and 4 (and that gem is made by Heroku team as well).

On rails 5, try making the changes in production.rb that are suggested on this page rails_12f

Finally I just added this :
config.serve_static_files = true
in environements/production.rb
Note: flag deprecated in Rails 5.0 in in favor of config.public_file_server.enabled

Related

Rails Web Console and development error not showing up

I recently updated my rails application to rails 5.2 and Ruby Version 2.3.3 to my surprise, a development error in the browser is not showing up as error anymore but with the message
We are sorry, something went wrong
If you are the application owner please check logs
while,
config.consider_all_requests_local = true
is present in my development.rb file.
and running RAILS_ENV=development rails s too doesn't help
And all changes I made was by following the rails guide only.
A similar thread exists with no conclusion: here
Thanks in advance
I had the same issue too, when I checked in my config/environments/development.rb the config.consider_all_requests_local = true was set to false.
After that for web console debugging I install gem "better_errors" and everything works fine. Also make sure gem web-console is also installed.
I tried to update the 'web-console' gem and it works.

Active Admin Layout Not Display Proper In Production Environment

My Active Admin Layout Not Comes in Production Environment.
I added in Gemfile
gem 'activeadmin', github: 'gregbell/active_admin'
See My Active Admin Page
Help me Please.
Thanks In Advance
Im using Rails 4 and after running the server in RAILS_ENV=production i would get the same layout as you did, although it works in the development environment. after searching in the web for different answers that one that work for me was the next. Heroku does NOT compile files under assets pipelines in Rails 4 i find the answer here.
add rails_12factor to your gemfile
gem 'rails_12factor', group: :production
then
bundle install
and then restart your server
i did some modifications to config/application.rb file but it never worked for me (somthing to do with precompile assets) therefor i dont think it's necessary.
hope it helps

production.log empty on Rails 4 / Capistrano / Passenger / Nginx server (digital ocean)

I have set up a rails 4 server on Ubuntu 12.04 using Capistrano, Nginx, Passenger, Postgres, Redis/Resque
Everything is working great, except that the production.log file is always empty.
I have tried a variety of configuration changes in production.rb to no avail.
It's definitely not a permissions issue, as the permissions on both the log dir and each of the logs are wide open (777)
Can anyone hep me figure out how to get basic logging working?
The culprit was Heroku's rails_12factor gem
Removing that gem from the Gemfile, now the logs are working as expected.
# group :production do
# gem 'rails_12factor'
# end
To clarify, the rails_12factor gem was responsible, but that's only because it includes rails_stdout_logging, which is the real culprit, however, due to it's intended behavior to "ensure that your logs will be sent to standard out."
Check with the log levels in production.rb file, config.log_level = :debug will display it's errors. Also make sure the server is running production mode, in case you have not made any changes any configuration files for rails env, production mode is by default.

rails 4 enabled rails to serve static assets: is it correct? (on heroku)

Environment: heroku
Rails: 4
Ruby: 2
We deployed an app to heroku, and it seemed as though anything in the public folder was not accessible (didn't see the static file so the router kicked in and then complains about no route matching).
To get around this, we set
# Rails 4 only flag
config.serve_static_assets = true
in our production.rb file. Is this really the best way to handle this? Or did we fail to configure the app some how to be hosted on heroku properly?
This is deprecated in Rails 4.2, and it is now an alias slated to be removed in Rails 5.0
config.serve_static_assets = true
It should be changed to:
config.serve_static_files = true
In previous Rails versions, Heroku injected a plugin that enabled serving of static assets so this issue didn't exist. As this plugin system was removed in Rails 4, they now created a gem which does the same. You enable it in your Gemfile via:
gem 'rails_12factor', group: :production
See Getting Started with Rails 4.x on Heroku
You could also of course use a CDN for your assets, but you're not required to.
For Rails 5+ work on twelve-factor platforms out of the box and the gem is no longer required
As Dean Winchester mentioned it, it is a good idea to use a CDN for your static assets. In fact when using only Heroku your Rails application would have to be responsible to serve static assets since Heroku Cedar architecture will not do that for you.
Setting config.serve_static_assets = true is the way to go if you don't want to configure a CDN and use only Heroku.
The rails guides are wrong. Try...
config.assets.serve_static_files = true

Rails 3.1rc4 and 404 not found when accessing assets

I'm trying to port my rails 3.0.7 project to rails 3.1
I have Phusion Passenger running on nginx + rvm.
There is config.assets.enabled = true in my application.rb file.
I created empty rails 3.1 project and copied my app directory, routes.rb and application.rb files over it. I moved everything from public to app/assets (app/assets/stylesheets etc).
When I'm trying to access assets (application.css/application.js), I'm getting 404 not found error, but I can see them in app/assets/stylesheets/application.css and app/assets/javascripts/application.js.
Help me please.
UPD: Thanks to Devin M for the idea, I removed css,js,gif,png and jpg extensions from nginx.conf ("serve static files directly") and everything started to work.
I came to this question with a similar problem (everything was giving a 404) I found that Rails 3.1.0.rc4 has a problem with gem 'sprockets'
In your Gemfile set:
gem 'sprockets', '= 2.0.0.beta.10'
Note: you may have to manually override your Gemfile.lock before you bundle install
Usually this is a problem with the nginx config not set up to serve things correctly. Double check your config files.

Resources