получает это сообщение об ошибке в моем терминале при попытке заполнить данные csv:
rake aborted! ActiveRecord :: AssociationTypeMismatch: ожидается год (# 70340979867760), получен 1967, который является экземпляром Integer (# 70340969823320)
вот мой код файла граблей:
require 'csv'
namespace :albums do
desc "pull albums data into database"
task seed_albums: :environment do
#drop the old table data before importing the new stuff
Albums.destroy_all
CSV.foreach("lib/assets/Albums.csv", :headers =>true) do |row |
puts row.inspect #just so that we know the file's being read
#create new model instances with the data
Albums.create!(
name: row[0],
year: row[1].to_i)
end
end
end
вот моя схема код:
create_table "albums", force: :cascade do |t|
t.string "name"
t.integer "year"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
и вот мой код контроллера:
class AlbumsController < ApplicationController
before_action :set_albums, only: [:show, :edit, :update, :destroy]
# GET /albums
# GET /albums.json
def index
@albums = Albums.all
end
# GET /albums/1
# GET /albums/1.json
def show
end
# GET /albums/new
def new
@albums = Albums.new (params[:album])
end
# GET /albums/1/edit
def edit
end
# POST /albums
# POST /albums.json
def create
@albums = Albums.new
respond_to do |format|
if @albums.save
format.html { redirect_to @albums, notice: 'albums was successfully created.' }
format.json { render :show, status: :created, location: @albums }
else
format.html { render :new }
format.json { render json: @albums.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /albums/1
# PATCH/PUT /albums/1.json
def update
respond_to do |format|
if @albums.update(albums_params)
format.html { redirect_to @albums, notice: 'albums was successfully updated.' }
format.json { render :show, status: :ok, location: @albums }
else
format.html { render :edit }
format.json { render json: @albums.errors, status: :unprocessable_entity }
end
end
end
# DELETE /albums/1
# DELETE /albums/1.json
def destroy
@albums.destroy
respond_to do |format|
format.html { redirect_to albums_url, notice: 'albums was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_albums
@albums = albums.find(params[:id])
end
# Only allow a list of trusted parameters through.
def albums_params
params.require(:albums).permit(:name, :term)
end
end
Заранее спасибо