html (rails) 上显示的数据库数据
Database data displaying on html (rails)
我正在制作一个 rails 应用程序,用户可以用它来购买产品。一切正常,然后我调整了products#index
页面,现在数据库中的数据显示在页面<div>
下的html上;
[#<Product id: 1, name: "Green", description: "coming from the hills of the emerald triangle, thi...", strain: "Sativa", price: #<BigDecimal:7fbe558f8228,'0.2E2',9(18)>, image_file_name: "http://i.imgur.com/NZkyXpr.jpg", created_at: "2015-04-12 22:56:42", updated_at: "2015-04-12 22:56:42", gram_price: nil, eighth_price: nil, quarter_price: nil, product_type: nil>, #<Product id: 3, name: "Sour Diesel", description: "Sour, sometimes called Sour D, is an invigo...", strain: "Hybrid", price: #<BigDecimal:7fbe55902bd8,'0.2E2',9(18)>, image_file_name: "http://i.imgur.com/RUHZAXQ.jpg", created_at: "2015-04-13 01:42:35", updated_at: "2015-04-13 01:42:35", gram_price: nil, eighth_price: nil, quarter_price: nil, product_type: nil>, #<Product id: 2, name: "Grand Daddy Purp", description: "Introduced in 2003 by Ken Estes, Granddaddy Purple...", strain: "Indica", price: #<BigDecimal:7fbe559015d0,'0.2E2',9(18)>, image_file_name: "http://i.imgur.com/8O5kXeL.jpg", created_at: "2015-04-13 01:41:17", updated_at: "2015-04-13 07:31:14", gram_price: nil, eighth_price: nil, quarter_price: nil, product_type: nil>]
这是我的索引页,还有我的控制器
index.html.erb
<section class="product-page">
<div class="container">
<div class="row text-center">
<%= @products.each do |product| %>
<div class="product col-md-4 text-center">
<h2><%= link_to product.name, product_path(product.id) %></h2>
<%= link_to image_tag(product.image_file_name),
product_path(product.id), :class => 'img-responsive' %>
<div class="product-info">
<div class="product-info-left"><%= product.descrip %></div>
<div class="product-info-right"><%= product.price %></div>
</div>
</div>
<% end %>
</div>
</div>
</section>
products_controller.rb
class ProductsController < ApplicationController
def index
@products = Product.all
end
def show
@product = Product.find(params[:id])
end
end
有谁知道为什么数据库中的数据会显示在我的 html 页面上?我忘记关闭标签了吗,我的控制器里有东西吗?如果我的描述不清楚,我还可以附上一张显示它的外观的图片。任何提示将不胜感激。
<%= @products.each do |product| %>
必须
<% @products.each do |product| %>
我正在制作一个 rails 应用程序,用户可以用它来购买产品。一切正常,然后我调整了products#index
页面,现在数据库中的数据显示在页面<div>
下的html上;
[#<Product id: 1, name: "Green", description: "coming from the hills of the emerald triangle, thi...", strain: "Sativa", price: #<BigDecimal:7fbe558f8228,'0.2E2',9(18)>, image_file_name: "http://i.imgur.com/NZkyXpr.jpg", created_at: "2015-04-12 22:56:42", updated_at: "2015-04-12 22:56:42", gram_price: nil, eighth_price: nil, quarter_price: nil, product_type: nil>, #<Product id: 3, name: "Sour Diesel", description: "Sour, sometimes called Sour D, is an invigo...", strain: "Hybrid", price: #<BigDecimal:7fbe55902bd8,'0.2E2',9(18)>, image_file_name: "http://i.imgur.com/RUHZAXQ.jpg", created_at: "2015-04-13 01:42:35", updated_at: "2015-04-13 01:42:35", gram_price: nil, eighth_price: nil, quarter_price: nil, product_type: nil>, #<Product id: 2, name: "Grand Daddy Purp", description: "Introduced in 2003 by Ken Estes, Granddaddy Purple...", strain: "Indica", price: #<BigDecimal:7fbe559015d0,'0.2E2',9(18)>, image_file_name: "http://i.imgur.com/8O5kXeL.jpg", created_at: "2015-04-13 01:41:17", updated_at: "2015-04-13 07:31:14", gram_price: nil, eighth_price: nil, quarter_price: nil, product_type: nil>]
这是我的索引页,还有我的控制器
index.html.erb
<section class="product-page">
<div class="container">
<div class="row text-center">
<%= @products.each do |product| %>
<div class="product col-md-4 text-center">
<h2><%= link_to product.name, product_path(product.id) %></h2>
<%= link_to image_tag(product.image_file_name),
product_path(product.id), :class => 'img-responsive' %>
<div class="product-info">
<div class="product-info-left"><%= product.descrip %></div>
<div class="product-info-right"><%= product.price %></div>
</div>
</div>
<% end %>
</div>
</div>
</section>
products_controller.rb
class ProductsController < ApplicationController
def index
@products = Product.all
end
def show
@product = Product.find(params[:id])
end
end
有谁知道为什么数据库中的数据会显示在我的 html 页面上?我忘记关闭标签了吗,我的控制器里有东西吗?如果我的描述不清楚,我还可以附上一张显示它的外观的图片。任何提示将不胜感激。
<%= @products.each do |product| %>
必须
<% @products.each do |product| %>