html - 在 rails 4.2.4 的布局文件夹中产生的不同标题元素

标签 html css ruby-on-rails

我对使用 Rails 4.2.4 编程和构建我的第一个电子商务 Web 应用程序很陌生

我的 application.html.erb 的 header 中有一个价格容器,它在 show.html.erb 和 index.html.erb 页面中产生。

问题:我只希望价格容器在显示页面(不是索引)上产生。

我试过删除 <% content_for :head do %>在索引页面上,但价格容器保留在此特定页面上。

如果能提供指导,我将不胜感激。下面的屏幕截图和代码。

show.html.erb index.html.erb

My application.html.erb page

<!DOCTYPE html>
<html lang="en">
<head>  
  <title>One Month Growth Hacking</title>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, user-scalable=no">
  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,700,300,800">

  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => false %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => false %>
  <%= csrf_meta_tags %>
</head>
<body>
    <div id="content" class="container">
        <header id="content-header">
            <div id="price-container">
                <span class="glyphicon glyphicon-tag"></span><span class="price">$4.99</span>
            </div>
            <%= yield :head %>
        </header>

        <%= yield %>

</div>

My index.html.erb page

<% content_for :head do %>
  <%= image_tag('skincare.png', id: 'content-header-img', alt: 'check out our products') %>
<% end %>   

<section id="article-title" class="row clearfix">
    <article id="details-article">
        <h1 id="article-title">Nippon Beauty Products</h1>
    </article>
</section>

<section id="products">
<% @products.each do |product| %>
     <div class="product clearfix">
       <a href="<%=product_path(product) %>"</a>
        <div class="product-image-container">
         <img src="<%= asset_path product.thumbnail_image_name %>" alt="<%= product.title %>"/>
         <span class="product-price">$<%= product.price %></span>
        </div>
       <p class="product-title"><%= product.title %></p></a>
     </div>
<% end %>

 </section>

最佳答案

你能从你的 application.html.erb 中删除它吗

<div id="price-container">
  <span class="glyphicon glyphicon-tag"></span><span class="price">$4.99</span>
</div>

然后在您的 show.html.erb 文件中,将其添加到图像标签之前的 :head 内容中

<% content_for :head do %>
  -> put it here <-
  <%= image_tag('skincare.png', id: 'content-header-img', alt: 'check out our products') %>
<% end %>

关于html - 在 rails 4.2.4 的布局文件夹中产生的不同标题元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35920219/

相关文章:

ruby-on-rails - ruby rails : Authlogic Facebook integration: Link accounts with user input instead of automatically using email address

ruby-on-rails - 403 禁止使用 rails/apache/passenger 访问

c# - 替换 <td> 标签内的 <p>、<div> 标签?

php - 什么会影响我的代码以获得巨大的字体大小变化?

javascript - 上传后如何在弹出窗口中显示图像?

html - 使用 flex 防止 div 在响应式布局中重叠

html - 通过 CSS 强制自动换行

javascript - 为什么 jquery 脚本不起作用?

html - 当鼠标悬停在其中一个元素上时,如何为共享一个类的所有元素添加边框?

ruby-on-rails - 如何使 Ruby 字符串对文件系统安全?