简体   繁体   English

在Rails电子商务网站上为ruby添加单个产品页面

[英]Adding individual product pages for ruby on rails e-commerce site

Hi I am having trouble showing an individual page for a product on ruby on rails for an e-commerce site, my code is as follows for the show view: 嗨,我在电子商务网站的栏杆上显示红宝石产品的单个页面时遇到麻烦,我的代码如下所示:

<div class="name">
  <%= @product.name %>
</div>

<div class="description">
  <%= @product.description %>
</div>

<div class="images">

<div class="image_url">
<%= @product.image_url %>
</div>

<div class="image_url1">
  <%= @product.image_url1 %>
</div>

<div class="image_url2">
  <%= @product.image_url2 %>
</div>

<div class="image_url3">
  <%= @product.image_url3 %>
    </div>
 </div>

 <div class="price" >
   <%= @product.price %>
 </p>

Here is the code for the controller: 这是控制器的代码:

def show
@product = Product.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @product}
end
end

What should I add to be able to see an individual products page which shows the name images, description, price as it works fine when I am indexing the products? 我应该添加什么才能看到显示名称图像,说明和价格的单个产品页面,因为在索引产品时可以正常使用?

You need an <img> tag to show an image, which can be generated with the image_tag method. 您需要一个<img>标记来显示图像,该图像可以使用image_tag方法生成。 Try this: 尝试这个:

<div class="image_url">
  <%= image_tag(@product.image_url) %>
</div>

Here's more information on the image_tag method 这是有关image_tag方法的更多信息

You may also want to hide that div if one of the images doesn't exist: 如果其中一张图片不存在,您可能还想隐藏该div

<% if !@product.image_url3.nil? && !@product.image_url3.blank? %>
  <div class="image_url3">
    <%= image_tag(@product.image_url3) %>
  </div>
<% end %>

我终于可以正常工作了,我正在对错误的视图文件进行更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM