ruby-on-rails - 当我返回菜单页面时,背景图像未显示

标签 ruby-on-rails google-chrome paperclip haml

当我打开页面背景图像时显示,但返回页面后图像未显示在 chrome 中(在 safari 中均正常)

使用回形针

在我看来(HAML + Rails 上的一些代码):

#list-projects
 - @projects.each do |project|
  .project{:style => "background: url('#{project.photo.url(:preview_16x9)}') no-repeat ;"}

获取此 html:

<div id="list-projects">
          <div class="project" style="background: url('/system/projects/photos/000/000/001/preview_16x9/franchi.jpg?1392386916') no-repeat ;">
            <a href="/projects/1"> </a>
            <div class="description">
              <h3>Shops number two</h3>
              <h4>Square —
              305      м<sup>2</sup>.</h4>
            </div>
          </div>
          <div class="project" style="background: url('/system/projects/photos/000/000/002/preview_16x9/franchi.jpg?1392310632') no-repeat ;">
            <a href="/projects/2"> </a>
            <div class="description">
              <h3>Shops number one</h3>
              <h4>Square —
              305      м<sup>2</sup>.</h4>
            </div>
          </div>

</div>

更新:

此代码生成的导航(rails、haml)

%nav#mainmenu
 %li{class: current_page?(root_path)    && 'active' }
  = link_to_unless_current 'Projetcs', root_path
 %li{class: current_page?(contacts_path) && 'active' }
  = link_to_unless_current 'Contacts', contacts_path

最佳答案

通过添加#{request.protocol}#{request.host_with_port}解决

#project{:style => "background: url('#{request.protocol}#{request.host_with_port}#{project.photo.url}') no-repeat ;"}<

这是涡轮链接 gem 问题。谢谢core2juan

关于ruby-on-rails - 当我返回菜单页面时,背景图像未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21840260/

相关文章:

ruby-on-rails - 使用回形针 gem 从种子文件上传图像

javascript - Rails 4 上的 TinyMCE, Assets 管道不适合我

html - 我的 CSS 未在 Internet Explorer 11 和 Firefox 中加载!仅适用于 Chrome

ruby-on-rails - 在回形针插件中异步生成附加样式

css - 在 Firefox 和 IE 中,-webkit-print-color-adjust 的替代项是什么

node.js - 为什么我不能使用 Puppeteer 在 exposeFunction() 函数中访问 'window'?

ruby-on-rails - 如何使用 Rails 中的 Paperclip 将文件系统中的图像添加到模型中?

ruby-on-rails - 具有设计嵌套属性的未知属性 'user_id'

ruby-on-rails - 在模型表上使用 default_scope 时出现问题

javascript - 在 Rails 的 Gmaps 中默认打开 infoWindow