Auto generate models on creation of other models in Ruby on Rails -


i have model called video has many statuses. want create status of each kind , add @video.statuses in def create of videoscontroller.

in videoscontroller, have:

 def create     @video = video.new(params[:video])     kind.all.each |f|       @video.statuses.new(:kind =>f, :kind_id=>f.id,:comment =>"", :time_comp => nil, :completed =>false, :video_id =>@video.id)     end     respond_to |format|       if @video.save         format.html { redirect_to @video, notice: 'video 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 

however, returns error says video not saved because statuses invalid. validation in entire project in status , merely checks there video_id. i'm confused why i'm getting error , appreciate help!

https://github.com/ninajlu/videos

you trying create statuses before saving @video, has no @video.id , invalid following validation rule


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -