가 나는 CSV는 레일이 속성은
5.이 목록 될 것입니다 간단한 모델을 가지고에 루비에서 레이크 작업과 파일을 대량로드에 노력하고있어 레일 응용 프로그램에 존재 영화 산업. 난 레일 애플 리케이션을 실행하고 성공적으로 새로운 영화 승/웹 애플 리케이션을 만들 수 있습니다. 내가 레이크 작업을 실행하면, 그것은 UnknownAttributeError 실패 : 여기
create_table "movies", force: :cascade do |t|
t.string "Title"
t.string "Genre"
t.string "Rating"
<snip>
end
의 내 (직선 ... 비계 점 만점) 방법을 만들
: 알 수없는 속성 '제목'영화에 대한여기 내 스키마의
desc "bulk load movies in the db"
task :upload_movies => [ :environment] do
require 'csv'
f = "#{Rails.root}/tmp/movies.csv"
raise "#{f} does not exist. Stoping import of movies" if !File.exists?(f)
CSV.foreach(f, :headers => true) do |row|
Movie.create!(row.to_hash)
end
end
:
def create
@movie = Movie.new(movie_params)
respond_to do |format|
if @movie.save
format.html { redirect_to @movie, notice: 'Movie was successfully created.' }
format.json { render :show, status: :created, location: @movie }
else
format.html { render :new }
format.json { render json: @movie.errors, status: :unprocessable_entity }
end
end
end
여기 내 레이크 작업의 나는 응용 프로그램을 통해 동영상을 추가
는 서버 콘솔은 다음과 같이 제대로 작동을 보여줍니다
(0.1ms) BEGIN SQL (1.3ms) INSERT INTO "movies" ("Title", "Genre", "Rating", "Lead", "Director", "Year", "Type", "Duration", "Theater", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING "id" [["Title", "the ballerina"], ["Genre", "sci fi"], ["Rating", "PG"], ["Lead", "random"], ["Director", "local"], ["Year", 2010], ["Type", "3D"], ["Duration", 90], ["Theater", "3/4"], ["created_at", 2016-12-24 15:05:21 UTC], ["updated_at", 2016-12-24 15:05:21 UTC]] (0.6ms) COMMIT Redirected to http://localhost:3000/movies/1
내 CSV 파일의 상단은 다음과 같습니다 : 여기
Title,Genre,Rating,Lead,Director,Year,Type,Duration,Theater
The Avengers: Age of Ultron 3D,Action,PG-13,Robert Downey Jr.,Joss Whedon,2015,3D,141,3/4
는 레이크 작업의 출력입니다 - (이 예제에서는 마이그레이션을 실행 했으므로이 커뮤니티에서 내 DB가 최신 버전인지 알 수 있습니다 ...)
$ rake db:migrate
$ rake upload_movies
rake aborted!
ActiveModel::UnknownAttributeError: unknown attribute 'Title' for Movie.
/Users/ustonma/dev/stone/gl7movies/lib/tasks/movieUpload.rake:11:in `block (2 levels) in <top (required)>'
/Users/ustonma/dev/stone/gl7movies/lib/tasks/movieUpload.rake:10:in `block in <top (required)>'
Tasks: TOP => upload_movies
(See full trace by running task with --trace)
$
무엇이 누락 되었습니까? - 감사합니다.
은 업로드중인 CSV 파일을 소문자 열 머리글을 사용하여 업데이트하려고했습니다. 레이크 작업에서와 같은 결과가 나온다 :'$ rake upload_movies 레이크가 중단되었다! ActiveModel :: UnknownAttributeError : Movie의 'title'알 수없는 속성입니다. /Users/ustonma/dev/stone/gl7movies/lib/tasks/movieUpload.rake:11 : 블록 (2 레벨) <맨 위 (필수)> ' /사용자/ustonma/dev/stone/gl7movies/lib /tasks/movieUpload.rake:10:in 블록이 <맨 위 (필수)> ' 작업 : TOP => upload_movies (--trace로 작업을 실행하여 전체 추적 참조)' – user2711286