On 9 May 2013 22:41, Jessica Lu <loppi...@gmail.com> wrote:
> I have a model called Video that has many statuses. I want to create a
> status of each kind and add it to @video.statuses in the def create of
> VideosController.
>
> In VideosController, I have:
>
>  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)

I think you probably want @video.statuses.create( .. ) so that the
status objects will be saved.  See the Rails Guide on ActiveRecord
Associations for more detail.

Colin

>     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
>
> However, this returns an error that says that the video could not be saved
> because the Statuses were invalid. The only validation in my entire project
> is in status and it merely checks that there is a video_id. I'm very
> confused why I'm getting this error and would appreciate any help!
>
> https://github.com/ninajlu/videos
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-talk+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-talk/-/V3dUCt6Vl-0J.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to