当我使用rails s
运行服务器时,一切正常,但是当我在生产模式下运行服务器时,它看起来像:without stylesheets and other assets。我需要做些什么才能解决这个问题?
在production.rb
集
config.public_file_server.enabled = true
config.assets.compile = true
然后像这样运行服务器
RAILS_ENV=production rails assets:precompile
RAILS_ENV=production rails server
你预编译了你的资产吗?尝试在本地运行:
RAILS_ENV=production bundle exec rake assets:precompile
将创建一个public/assets
目录,然后将更改提交到您的存储库。现在应在生产服务器上检测资产。
您能否向我们提供一个如何链接到CSS和JS文件的示例?它看起来应该是这样的(这是.haml而不是.erb)
= stylesheet_link_tag 'default/application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag 'application', 'data-turbolinks-track' => true