【问题标题】:Rails app not picking up styles in application.cssRails 应用程序没有在 application.css 中选择样式
【发布时间】:2012-11-24 18:32:48
【问题描述】:

我的 rails 应用程序目前拒绝在我的生产服务器(linode 服务器)上的 application.css 中获取 body 标签样式,但它可以在我的 localhost:3000 上运行。 我的资产管道如下所示

 *= require bootstrap.min
 *= require bootstrap_customization
 *= require datepicker
 *= require select2
 *= require_self
 *= require_tree .

我尝试过切换 require_self 和 require_tree 的位置,但它并没有改变任何东西。我想指出所有其他样式都被选中了,只是在 application.css 中没有被选中的 body 标签。这是body标签的代码

body{
background: transparent url('/assets/bg2.png');
font-family: 'Lucida Grande', Verdana, Helvetica, Arial;
}

我已尝试在 css 中添加类以更具体地对其范围进行调整,并且我已确保图像上没有允许访问它的权限。但它只显示一个白色背景,并使用此标签上方的 body 标签样式(具有背景图像的标签),但仅此而已。这仅在生产中发生,该背景图像在我的本地主机上完美显示,这很奇怪有人知道吗?

【问题讨论】:

  • 如果你在生产中,你确定你以前不需要编译资产吗? bundle exec rake assets:precompile
  • 我已经这样做了好几次了,我已经将我的生产环境设置为资产预编译 = true

标签: css ruby-on-rails background-image asset-pipeline production-environment


【解决方案1】:

如果您使用的是 rails 3,请尝试使用 rails 提供的资产管道功能,例如:

body {
  background: transparent image_url('bg2.png');
  font-family: 'Lucida Grande', Verdana, Helvetica, Arial;
}

【讨论】:

    【解决方案2】:

    需要清除服务器的缓存。同时执行rake assets::clean 将删除开发和生产中的所有缓存文件(无论您在哪里运行)

    【讨论】:

      猜你喜欢
      • 2016-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-27
      相关资源
      最近更新 更多