我有一個稱爲視頻的模型,它具有許多狀態。我想創建每種類型的狀態並將其添加到VideosController的def create中的@ video.statuses中。在Ruby on Rails中創建其他模型時自動生成模型
在VideosController,我有:
def create
@video = Video.new(params[:video])
Kind.all.each do |f|
@video.statuses.new(:kind =>f, :kind_id=>f.id,:comment =>"", :time_comp => nil, :completed =>false, :video_id =>@video.id)
end
respond_to do |format|
if @video.save
format.html { redirect_to @video, notice: 'Video was successfully created.' }
format.json { render json: @video, status: :created, location: @video }
else
format.html { render action: "new" }
format.json { render json: @video.errors, status: :unprocessable_entity }
end
end
end
然而,這將返回,指出該視頻無法保存,因爲的狀態是無效的錯誤。我整個項目中唯一的驗證是狀態,它只是檢查是否有video_id。 我很困惑,爲什麼我得到這個錯誤,並會感謝任何幫助!
https://github.com/ninajlu/videos