开发者

NoMethodError in ContainerformatsController#create undefined method `yuvstreams' for #<Containerformat:0x450f560>

开发者 https://www.devze.com 2023-01-16 10:26 出处:网络
I am getting this error, I don\'t know what happened, it\'s been working fine few days before but it\'s not working now. This is the code:

I am getting this error, I don't know what happened, it's been working fine few days before but it's not working now. This is the code:

@containerformat = Containerformat.new(params[:containerformat])

if @containerformat.containerFmt == 'TS'
  @containerformat = Containerformat.new(params[:containerformat])
  @transportstream =
    @containerformat.transportstreams.build(params[:transportstream])
  @transportstream.save
  @program = @transportstream.programs.build(params[:program])
  @program.save
  @user = @containerformat.users.build(params[:user])
  @user.save

  if params[:videoCodec_id]!= nil
    @stream = @program.streams.build(params[:stream])
    @stream.videocodec = Videocodec.find(@stream.videoCodec_id)
    @stream.save
  end
  if params[:audioCodec_id]!= nil
    @stream = @program.streams.build(params[:stream])
    @stream.audiocodec = Audiocodec.find(@stream.audioCodec_id)
    @stream.save
  end

end

if @containerformat.containerFmt == 'PS'
  @programstream =
    @containerf开发者_StackOverflowormat.programstreams.build(params[:programstream])
  @subtitle = @programstream.subtitles.build(params[:subtitle])
  @subtitle.save
  @programstream.save
  @stream = @programstream.streams.build(params[:stream])
  @user = @containerformat.users.build(params[:user])
  @user.save

  if params[:videoCodec_id]!= nil
    @stream = @programstream.streams.build(params[:stream])
    @stream.videocodec = Videocodec.find(@stream.videoCodec_id)
    @stream.save
  end
  if params[:audioCodec_id]!= nil
    @stream = @programstream.streams.build(params[:stream])
    @stream.audiocodec = Audiocodec.find(@stream.audioCodec_id)
    @stream.save
  end

end

if @containerformat.containerFmt == 'YUV'
  @yuvstream = @containerformat.yuvstreams.build(params[:avistream])
  #@subtitle = @yuvstream.subtitles.build(params[:subtitle])
  #@subtitle.save
  @yuvstream.save
  @stream = @yuvstream.streams.build(params[:stream])
  @user = @containerformat.users.build(params[:user])
  @user.save

  if params[:videoCodec_id]!= nil
    #@stream = @programstream.streams.build(params[:stream])
    #@stream.videocodec = Videocodec.find(@stream.videoCodec_id)
    #@stream.save
  end
  if params[:audioCodec_id]!= nil
    #@stream = @programstream.streams.build(params[:stream])
    #@stream.audiocodec = Audiocodec.find(@stream.audioCodec_id)
    #@stream.save
  end

end


if @containerformat.containerFmt == 'AVI'
  @avistream = @containerformat.avistreams.build(params[:avistream])
  @avistream.save
  @stream = @avistream.streams.build(params[:stream])
  @user = @containerformat.users.build(params[:user])
  @user.save

  if params[:videoCodec_id]!= nil
    @stream = @avistream.streams.build(params[:stream])
    @stream.videocodec = Videocodec.find(@stream.videoCodec_id)
    @stream.save
  end
  if params[:audioCodec_id]!= nil
    @stream = @avistream.streams.build(params[:stream])
    @stream.audiocodec = Audiocodec.find(@stream.audioCodec_id)
    @stream.save
  end
end

I have yuvstreams as table in my database like other tables avisteams, programstreams table.


You need a has_many :yuvstreams in your Containerformat class.

This defines the relationship between containerformats and yuvstreams from the containerformat point of view. You can find more details in the api docs for the has_many method. Basically though, without that you can't refer to yuvstreams from a containerformat.

One additional point on style. Typically rails uses an _ and camel case to make names more readable. So you would have YuvStream and ContainerFormat as your class name and has_many :yuv_streams as your association definition. Rails expects this kind of naming and can sometimes make educated guesses about things if you use it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号