Я настраиваю свой начальный файл для добавления некоторых данных в мое приложение Rails 5.Когда я запускаю rake db:seed
Я получаю эту ошибку
rake aborted!
ActiveModel::UnknownAttributeError: unknown attribute 'excerpt' for List.
Не могу понять, почему я получаю это.Я использую PostgreSQL в качестве БД и Rails 5.2.Я пытаюсь построить API.
Я установил БД, выполнил миграцию, но seed не работает.
У меня есть еще 2 модели и контроллер для предметов.
Файл с семенами:
List.create(title:"West Sweden Road Trip", excerpt:"A cool road trip with stops in harbors of the coast")
Моя модель:
class List < ApplicationRecord
has_many :list_items
has_many :items, through: :list_items
end
Контроллер:
module Api::V1
class ListsController < ApplicationController
before_action :set_list, only: [:show, :update, :destroy]
# GET /lists
def index
@lists = List.order(:id)
render json: @lists
end
# GET /lists/1
def show
render json: @list
end
# POST /lists
def create
@list = List.new(list_params)
if @list.save
render json: @list, status: :created
else
render json: @list.errors, status: :unprocessable_entity
end
end
# PATCH/PUT /lists/1
def update
if @list.update(list_params)
render json: @list
else
render json: @list.errors, status: :unprocessable_entity
end
end
# DELETE /lists/1
def destroy
@list.destroy
if @list.destroy
head :no_content, status: :ok
else
render json: @list.errors, status: :unprocessable_entity
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_list
@list = List.find(params[:id])
end
# Only allow a trusted parameter "white list" through.
def list_params
params.require(:list).permit(:title, :excerpt, :description, :upvotes)
end
end
end
Моя схема:
ActiveRecord::Schema.define(version: 2018_10_14_135801) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "items", force: :cascade do |t|
t.integer "type"
t.string "name"
t.text "excerpt"
t.text "description"
t.string "url"
t.integer "upvotes"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "list_items", force: :cascade do |t|
t.bigint "list_id"
t.bigint "item_id"
t.text "description"
t.integer "position"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["item_id"], name: "index_list_items_on_item_id"
t.index ["list_id"], name: "index_list_items_on_list_id"
end
create_table "lists", force: :cascade do |t|
t.string "title"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_foreign_key "list_items", "items"
add_foreign_key "list_items", "lists"
end