问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/18562239/locomotivecms-assets-in-production