【问题标题】:Pandastream video uploading with rails使用 Rails 上传 Pandastream 视频
【发布时间】:2014-02-25 13:14:28
【问题描述】:

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

这是我的视频模型。

    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

【问题讨论】:

    标签: ruby-on-rails pandastream


    【解决方案1】:

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

    视频控制器

    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>
    

    【讨论】:

      猜你喜欢
      • 2012-06-22
      • 2014-02-24
      • 2014-03-11
      • 2015-10-29
      • 2015-06-10
      • 2017-09-03
      • 2016-01-12
      • 2015-07-05
      • 2015-12-28
      相关资源
      最近更新 更多