2011-09-17 4 views
0

Iain Hecker의 튜토리얼 : http://iain.nl/backends-in-rails-3-1으로 작성된 백엔드 관리자를 구축하려고 노력 중이며 Mongoid에 적용하려고합니다. 위의 코드와 Mongoid의 'attribute_names'대신 사용 하시겠습니까?

module Backend::ResourceHelper 

    def attributes 
    resource_class.attribute_names - %w(id created_at updated_at) 
    end 

end 

, 나는 다음과 같은 오류 얻고 있었다 : 그래서

undefined method `attribute_names' for Backend::User:Class 

을, 나는 해결책이 게시물 지적했습니다 : How can I get all field names of the Mongoid Document?

나는 'resource_class.fields를 사용하여 시도 .keys '대신'resource_class.attribute_names '를 사용하지만 다음과 같은 오류가 발생합니다.

app/views/backend/resource/_index.html.haml이 표시된 행 # 9

raised:undefined method `id' for [:where, {}]:Array 

추출 소스 (주위 라인 # 9) :

6: %th 
7: %tbody 
8: - collection.each do |resource| 
9: %tr[resource] 
10: - attributes.each do |attr| 
11: %td= resource.public_send(attr).to_s.truncate(20) 
12: %td 

..

답변

1
Contest.first.attributes.map { |attr, value| attr } 
=> ["_id", "closing_on", "created_at", "description", "entries", "name"] 
+0

감사합니다 나는 레일에 새로운 오전 당신이 좀 포인터를 제공 할 수 있다면 정말 감사하겠습니다 너 내쉬 !! – Jamal

관련 문제