2012-02-09 12 views
0

저는 Rails 2와 함께 Agile Web Development에 문제가있는 초보자입니다. Ruby verison 1.8.6. 책이 admin_controller.rb에 스캐 폴드 제품을 넣도록 지시했을 때 문제가 시작되었습니다. 선을 제거했는데 이제 다음과 같은 오류 메시지가 나타납니다. 라인 # 10 제기 관리자/index.html.erb을 표시 관리자 # 지수 에서NoMethodError in Admin # 색인

NoMethodError : 당신이 그것을 기대하지 않았을 때

당신은 전무 개체가 있습니다! Array의 인스턴스를 예상했을 수 있습니다.

여기 컨트롤러 /InstantRails-2.0-win/rails_apps/depot :

7:  <th>Image url</th> 
8: </tr> 
9: 
10: <% for product in @product %> 
11: <tr> 
12:  <td><%=h product.title %></td> 
13:  <td><%=h product.description %></td> 

RAILS_ROOT : C (라인 # 10 정도) nil.each

추출 소스를 평가하면서 오류가 발생한 정보 : admin_controller 클래스 AdminController <와 ApplicationController 끝 여기

뷰 정보입니다 : 조회수 \ 관리자 \의 index.html.erb

목록 제품

<table> 
    <tr> 
    <th>Title</th> 
    <th>Description</th> 
    <th>Image url</th> 
    </tr> 

<% for product in @product %> 
    <tr> 
    <td><%=h product.title %></td> 
    <td><%=h product.description %></td> 
    <td><%=h product.image_url %></td> 
    <td><%= link_to 'Show', product %></td> 
    <td><%= link_to 'Edit', edit_product_path(product) %></td> 
    <td><%= link_to 'Destroy', product, :confirm => 'Are you sure?', :method   => :delete %></td> 
     </tr> 
<% end %> 
</table> 

<br /> 

<%= link_to 'New product', new_product_path %> 

다음 모델 정보의

: 모델 \ product.rb 일류 상품 < 액티브 :: 자료 끝

어떤 조언을?

+0

관리자 용 컨트롤러의 모양은 어떻습니까? 색인 작업이 있습니까? 그 안에'@ product'를 설정하고 있습니까? – MrDanA

+0

관리자 컨트롤러가 비어 있습니다. 책은 나에게 오류 메시지를 준 제품인 비계를 제안했습니다. 여기에 현재의 컨트롤러가 있습니다. class AdminController yatta20

답변

3

는 컨트롤러에서 설정되지 않는 @products 것 같은데 당신은 또한보기에서 가능 오타가 :보기에

\ 관리자 \의 index.html.erb 변경 :

<% for product in @product %> 

에 :

<% for product in @products %> 

및 컨트롤러를 확인이 있습니다

admin_controller.rb

class AdminController < ApplicationController 

    def index 
    @products = Product.all 
    end 

end 
+0

도움 주셔서 감사합니다. 다음은 새로운 오류 메시지입니다. NoMethodError AdminController 번호 지수 정의되지 않은 메서드'모든 '번호의 <클래스 : 0x36aa614> RAILS_ROOT : C : /InstantRails-2.0-win/rails_apps/depot 응용 프로그램 추적 | 프레임 워크 추적 | 전체 추적 C : /InstantRails-2.0-win/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb : 1532 :'method_missing '에서 app/controllers/admin_controller .rb : 3 :'index '에 – yatta20

+0

글쎄, 그건 완전히 다른 것이고, 나는 이것이 이루어질 길을 두려워한다. 제품 모델을 가지고 계십니까? app/models/product.rb? – miked

+0

네,하지만 지금은 비어 있습니다. class Product yatta20