0

私は製品のある店を持っています。_product.html.erb製品の概要を含むパーシャルを作成し、それをインデックス ページとショー ページの両方に使用しています。

<h1>問題は、製品名を製品表示ページの見出しにしたいのですが<h2>、インデックス ページにあることです。<h1>インデックス ページに多くの製品があり、同じページに多数の s を配置する意味があるかどうかわからないため、これを行いたいと考えています。ショーページは、その商品しか持っていないので、ぜひ使いたいです<h1>

私がこれを行った方法は、以下のように部分的に if/else 句を使用することでしたが、少し面倒です。これを行うより良い方法はありますか?

product/_product.html.erb

<div class="product_partial">
  <% if params[:action] == "show" %>
    <h1><%= product.name %></h1>
  <% else %>
    <h2><%= product.name %></h2>
  <% end %>          
  <h3><%= product.description %></h3>
</div>  

製品/show.html.erb

<div class="product_show">
  <%= @product %>
  <%= @product.other_info %>    
</div>

製品/index.html.erb

<div class="product_index">
  <%= @products %>
</div>
4

1 に答える 1

2

多分このようなもの

product / _product.html.erb

<div class="product_partial">
    <<%= heading_tag %>><%= product.name %></<%= heading_tag %>>         
    <h3><%= product.description %></h3>
</div> 

product / show.html.erb

<div class="product_show">
    <%= render @product, :heading_tag => 'h1' %>
    <%= @product.other_info %>    
</div>

product / index.html.erb

<div class="product_index">
   <%= render @products, :heading_tag => 'h2' %>
</div>
于 2013-01-23T20:39:53.253 に答える