Pandastream video uploading with rails

181 Views Asked by At

I'm just in the process of getting video uploading in my app using pandastream, but i can't wrap my head around this attr_accessible rails 3 stuff that isn't in rails 4. I know it has something to do with strong params, but as to what to pass into the code is confusing me, thanks, here's some snippets.

Here's my video model.

    class Video < ActiveRecord::Base
  validates_presence_of :panda_video_id


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

And Video controller.

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
1

There are 1 best solutions below

0
On

I had a similar issue. I restructured the form to pass the information to the controller in a slightly different way. I was able to set everything up as follows:

VideoController

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

video/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>