多くのステータスを持つ Video というモデルがあります。各種類のステータスを作成し、VideosController の def create で @video.statuses に追加したい。
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 があることを確認するだけです。なぜこのエラーが発生するのか非常に混乱しており、助けていただければ幸いです!