Locomotivecms Assets in Production - ruby-on-rails

I have asked this question in the locomotivecms google groups, but haven't gotten any useful response yet. So, trying out here. I have a feeling the issue is not just a rails issue but has something to do with how the locomotivecms engine is implemented.
I installed the locomotivecms app as per the instructions here - http://doc.locomotivecms.com/guides/get-started/install-engine
The app runs fine in development mode.
I then precompiled the assets and started it in production mode (bundle exec unicorn_rails -E production). Now when I open the app in the browser, the stylesheets are not rendered. I have checked the public/assets and the fingerprinted stylesheet requested by the browser is present there. Yet it is not rendered correctly. This is what the chrome view resources shows:
It looks as if the stylesheet contains html. If I open it from the public/assets folder it contains css. I think Locomotive is intercepting the request and somehow not returning the css. Locomotive is open source, their code is on github - https://github.com/locomotivecms/engine.

The problem was not with Locomotivecms, it was a rails thing that I did not know about. I had following in production.rb:
config.serve_static_assets = false
This setting is right if you are running your app in Nginx or Apache in production. In which case they server the public assets. But if you are running your app on simply a rails server in production, like unicorn, webbrick, thin etc. then you need to set this setting to true in order for the rails server to serve assets from public folder. I set this to true, started the server (bundle exec unicorn_rails -E production) the assets were served fine.
More explanation on config.serve_static_assets can be found here: http://guides.rubyonrails.org/configuring.html

Related

Rails on Heroku - Site does not load - ActionView::Template::Error (The asset "image.jpg" is not present in the asset pipeline.)

I've build a simple website, using Rails so I can deploy it to Heroku. It runs perfectly locally, everything works fine. It deploys fine to Heroku but when opening the webpage (http://a-clean.herokuapp.com/) I get the following error displayed:
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
When I check the logs (running heroku logs in terminal) it shows the error:
ActionView::Template::Error (The asset "a_clean_sample_1.jpg" is not present in the asset pipeline.)
So far this is just a one-page website with a couple of partials. Here is the github repository: https://github.com/webbc99/a-clean
The image it's failing on is loaded in app/views/welcome/home.html.erb line 57.
Rails version 5.1.6, Ruby version 2.5.0
I've double checked that the images are in fact in the app/assets/images folder, and the image_tags are using the file extensions.
I've tried running heroku run rake assets:precompile, and I've tried using the rails12factor gem and also without it. I have tried changing config.assets.compile = false to true in the config/environments/production.rb which did get the page to load but all of the images were ignoring styling and were huge.
What is really confusing me is that I have deployed several other rails apps, same rails version, same ruby version, and none of these have had this issue before.
Here is a working app:
https://github.com/webbc99/presumptuous
https://presumptuous.herokuapp.com/
Any help would be greatly appreciated, been googling this for hours with no luck.
It's the simplest way to fix this problem is; You need to run as follows;
rails assets:precompile RAILS_ENV=production
git add .
git commit -m {message}
git push heroku master (push the code to the heroku again)
I tried to do it from your code and work fine.

Manifest requires output filename

I'm using Rails 3.0.10 and running rake assets precompile at production server and facing problem as manifest requires output filename.this code is already deployed on heroku server and working fine. Please provide a solution on this.

404 not found error for assets in rails 4 production enviroment

I am new to rails from java enviroment. I have few confusions in asset pipeline with rails 3 to 4.
Currently I am in rails 4.2.5
I created a sample app on my local environment.
I created a new js from inside app/assets/javascripts and referencing it from the view , everything seems to working fine on my local environment.
After this I thought to test with production env how it works. Here are the steps I did.
RAILS_ENV=production rake assets:clean assets:precompile [All the files created public/assets]
Started the server in production mode rails server -e production
Now when i browsed the page I am getting this error,
"NetworkError: 404 Not Found - http://localhost:3000/assets/application-c5c431cb7c0a202f831a634922aaf1d536712002ae74334fb03ba4698b32b84c.js" in firebug.
When searched few threads , they suggest to add config.assets.compile = true. But I do not think so this is what the solution is, as it slows down the app.
Please help.
By default Rails4 will return a 404 if an asset is not handled via an
external proxy such as Nginx.
- https://github.com/heroku/rails_serve_static_assets
I suggest you have a look at the rails_12factor gem, which includes the rails_serve_static_assets gem which will allow your Rails app to serve static assets (like your .js file).
Edit:
You may not need a gem for this (though I've not tried it):
config.serve_static_files configures Rails itself to serve static
files. 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.
- http://guides.rubyonrails.org/configuring.html
In Rails 5, this config method has been renamed to config.public_file_server.enabled, the rails_serve_static_assets gem handles the correct naming depending on version.

Rails 3.2.1 logging in Passenger, Thin, or Unicorn

I've tried those 3 hosting approaches for my Rails app, and no matter what I do, I can't get consistant logging when I run in the production environment.
For my tests, I created a blank app and tried to access the root directory. I would then add a users scaffold and rake the database.
If I turn RAILS_ENV to development, the log/devlopment.log works just fine, logging everything that I would expect.
When I turn RAILS_ENV to production, the log/production.log logs in a strange manner. In Passenger, I get the first routing error. Then nothing. When I restarted apache or nginx, I would get all the routing errors that I had caused since the first (logged) one, then the log would fail to write anything new until I restarted the underlying server. apache2/error.log would get logged to if I had a configuration issue. Then it only logged cache misses
With Thin and Unicorn, I only get errors about the static assets (I did not precompile the assets). Once I precompiled the assets, no more log messages appeared.
On all 3 setups, I would get precompilation messages (when I ran assets:precompile) in production.log (indicating that Rails could at least write to the log).
Does anyone have a Rails 3.2.1 app that is running on one of the deployment gems (Passenger, Thin, or Unicorn), that is logging correctly in production mode? I've spent 5 days working on this. I'm out of ideas.
Turns out its a reported issue in Rails 3.2.x. A fix has been submitted and will hopefully be released with Rails 3.2.2.
https://github.com/rails/rails/issues/4277

how do I run Rails 3.2 in production on my mac w/o getting cache: [GET /] miss

I've got this app running in development just right, but when I deploy the bugger, everything starts falling apart :(
So I tried grabbing the log while running development on my Mac - and then the exact thing, on the exact same platform (just switching from development to production environment). I believe to have not been messing with config/application.rb, config/environment.rb or config/environments/*
I've saved the screen output here: https://gist.github.com/1692260
Really could do with a helping hand - as this is baffling me :(
I ran into this error then realized my assets weren't compiled in production... I'd recommend trying
RAILS_ENV=production bundle exec rake assets:precompile
unless you know your stuff is being compiled. It slipped my mind because I'm so used to deploying to Heroku. This of course could only be the case in Rails >= 3.1
Have you tried changing to
config.serve_static_assets = true in production.rb
in production.rb?
Webbrick cannot serve static files. This is why you must have rails do it. If you use apache or nginx, they could serve the static files for you. But that requires some configuration.
You can find information on how to configure Apache and Nginx here.

Resources