1
- 我是一个Ruby的新手,我下面的书敏捷开发使用Rails 4,第95页
- 我创建了第二家分店控制器,并得到以下错误:未定义的局部变量或方法`产品'。有人知道缺少什么?
查看敏捷Web开发使用Rails 4 ::的ActionView模板:未定义的局部变量或方法`产品
<% if notice %>
<p id="notice"><%= notice %></p>
<% end %>
<h1>Your Pragmatic Catalog</h1>
<% @products.each do |product| %>
<div class="entry">
<%= image_tag(product.image_url) %>
<h3><%= product.title %></h3>
<%= sanitize(product.description) %>
<div class="price_line">
<span class="price"><%= products.price %></span>
</div>
</div>
<% end %>
class StoreController < ApplicationController
def index
@products = Product.order(:title)
end
end
.store {
h1 {
margin: 0;
padding-bottom: 0.5em;
font: 150% sans-serif;
color: #226;
border-bottom: 3px dotted #77d;
}
/* And entry in the store catalog */
.entry {
overflow: auto;
margin-top: 1em;
border-bottom: 1px dotted 77d;
min-height: 100px
img {
with: 80px;
margin-right: 5px;
margin-bottom: 5px;
position: absolute;
}
h3 {
font-size: 120%;
font-family: sans-serif;
margin-left: 100px;
margin-top: 0;
margin-bottom: 2px;
color: #227;
}
p, div.price_line {
margin-left: 100px;
margin-top: 0.5em;
margin-bottom: 0.8em;
}
.price {
color: *44a;
font-weight: bold;
margin-right: 3em;
}
}
}
嗨伊恩,感谢你暗示。我纠正了错误,但是如果我启动服务器,错误通知仍然存在:否它说:未定义的方法'each'为零:NilClass – Keeic 2014-10-05 08:39:25
不,它正在工作,我又保存了每一页。谢谢伊恩! – Keeic 2014-10-05 08:49:36