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