Skip to main content
 首页 » 编程设计

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

2024年11月24日66cloudgamer

当我打开页面背景图像时显示,但返回页面后图像未显示在 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