vendredi 14 avril 2017

Rails Paperclip paperclip-av-transcoder saving

thank you so much for any help. I've tried for a few days and I can't figure it out. I am trying to build a video upload form. To my surprise, I can not find much info on the topic.

I am using Paperclip with paperclip-av-transcoder. It seems to be letting me create a Video.new record but I can not get it to save @user.videos.build(video_params).

class VideosController < ApplicationController

  def new
    @user = User.find(current_user)
    @video = @user.build_video
  end

  def create
    @user = User.find(current_user)
    @video = @user.videos.build(video_params)
    if @video.save
       redirect_to admin_ad_pg_path, :flash => { :error => "It worked!" }
    else
       redirect_to admin_ad_pg_path, :flash => { :error => "Nope. Didn't work." }
    end
  end

  private
    def video_params
      params.require(:video).permit(:avatar)
    end
end


Video Model:

class Video < ApplicationRecord
    belongs_to :user
    has_attached_file :avatar, :styles => {
    :medium => { :geometry => "640x480", :format => 'flv' },
    :thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10 }
    }, :processors => [:transcoder]
    validates_attachment :avatar, content_type: { content_type: /\flv\/.*\Z/ }
end

User Model

class User < ApplicationRecord
has_many :videos
end



 Video Form:
<%= flash[:error] %>
      <%= form_for @video, url: user_videos_path(current_user), controller: "videos", method: 'post', :html => { multipart: true } do |f| %>
        <div class="form-group">
          <%= f.label :avatar %>
          <%= f.file_field :avatar, class: 'form-control' %>
        </div>
      <%= f.submit 'Submit',class: 'btn btn-default' %>
      <% end %>

Thanks, Matt

Aucun commentaire:

Enregistrer un commentaire