2016-06-27 17 views
0

현재 Ruby on Rails 앱을 작업 중입니다. Item 유형의 일부 객체를 만들려고하지만 이미 정의 된 내 모델을 찾을 수 없습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?NameError : 초기화되지 않은 상수 Item

조각 :

parse.rake (응용 프로그램/lib 디렉토리/작업) :

item = Item.create!(id: item_array['id'], path: item_array['path'], type: item_array['type'], lang: item_array['lang'], component: item_array['component'], 
      content: item_array['content'], title: item_array['title'], index: item_array['index'], tags: item_array['tags'], created_at: item_array['created_at'], 
      updated_at: item_array['updated_at'], keyword: item_array['keyword'], description: item_array['description']); 

item.rb (응용 프로그램/모델)

class Item < ActiveRecord::Base 
    self.table_name = 'my_items' 
    self.primary_key = 'id' 
end 

schema.rb (응용 프로그램/DB) :

ActiveRecord::Schema.define(version: 20160623145822) do 


create_table 'items', force: :cascade, options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8' do |t| 
    t.string 'path' 
    t.string 'type' 
    t.string 'lang' 
    t.string 'component' 
    t.json  'content' 
    t.string 'title' 
    t.integer 'index' 
    t.json  'tags' 
    t.string 'keyword' 
    t.text  'description', limit: 65535 
    t.datetime 'created_at',    null: false 
    t.datetime 'updated_at',    null: false 
    end 

end 

답변

2

클래스 항목에서 'my _items '하지만 스키마에서 테이블'항목 '을 생성하고 있습니다.

table_name을 삭제하고 model Item에서 primary_key를 변경할 수 있다고 생각합니다. RoR은 기본적으로 'items'테이블과 'id'기본 키를 사용하기 때문에.

+0

많은 덕분에 지금 작동합니다. – fr0styy