0

我正在使用 pandastream 在我的应用程序中上传视频,但我无法理解这个不在 rails 4 中的 attr_accessible rails 3 东西。我知道这与强大的参数有关,但至于传递到代码中的内容让我感到困惑,谢谢,这里有一些片段。

这是我的视频模型。

    class Video < ActiveRecord::Base
  validates_presence_of :panda_video_id


def panda_video
    @panda_video ||= Panda::Video.find(panda_video_id)
  end
end

和视频控制器。

class VideosController < ApplicationController
  def show
    @video = Video.find(params[:id])
    @original_video = @video.panda_video
    @h264_encoding = @original_video.encodings["h264"]
  end

  def new
    @video = Video.new(video_params)
  end

  def create
    @video = Video.create!(params[:video])
    redirect_to :action => :show, :id => @video.id 
  end

  def video_params

    params.require(:video).permit(:panda_video_id, :video)

  end
end
4

1 回答 1

2

我有一个类似的问题。我重组了表单,以稍微不同的方式将信息传递给控制器​​。我能够按如下方式设置所有内容:

视频控制器

class VideosController < ApplicationController
  def show
    @video = Video.find(params[:id])
    @original_video = @video.panda_video
    @h264_encoding = @original_video.encodings["h264"]
  end

  def new
    @video = Video.new
  end

  def create
    @video = Video.create!(video_params)
    redirect_to :action => :show, :id => @video.id
  end

  private
  def video_params
    params.permit(:title, :panda_video_id)
  end
end

视频/new.html.erb

<%= form_for @video do |f| %>

    <!-- field where the video ID will be stored after the upload -->
    <input id="panda_video_id" type="hidden" name="panda_video_id"/>

    <label>Title</label>
    <input type="text" name='title' placeholder="Give a title">

    <!-- upload progress bar (optional) -->
    <div class='progress'><span id="progress-bar" class='bar'></span></div>

    <!-- file selector -->
    <div id="browse">Choose file</div>

<% end %>

<script>
    var upl = panda.uploader.init({
        'buttonId': 'browse',
        'progressBarId': 'progress-bar',
        'onQueue': function(files) {
            $.each(files, function(i, file) {
                upl.setPayload(file, {'csrf': "<%= form_authenticity_token %>"});
            })
        },
        'onSuccess': function(file, data) {
            $("#panda_video_id").val(data.id)
        },
        'onComplete': function(){
            $("#new_video").submit();
        }
    });
</script>
于 2014-02-10T05:25:20.923 回答