0

現在、Ruby on Rails アプリに取り組んでいます。タイプ 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 (アプリ/データベース):

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
4

1 に答える 1

2

クラスItemではテーブル「my_items」を設定しますが、スキームではテーブル「items」を作成しています。

table_name を削除し、モデル Item の primary_key を変更できると思います。RoR はデフォルトでテーブル「items」と主キー「id」を使用するためです。

于 2016-06-27T11:56:02.747 に答える