rakoonise
rakoonise

Reputation: 539

Carrierwave not saving file

I have this app to upload a handwritten translation of a video through a little upload form. I then want to attach it to a video.

Here is my model:

require 'carrierwave/orm/activerecord'

class Video < ActiveRecord::Base
  attr_accessible :course, :qa_complete, :qa_id, :subject, :title, 
  :translate_complete, :translator_id, :type_complete, :typer_id, :video_id, :due_date, :translation_handwritten

  validates :video_id, :presence => true, :uniqueness => true #add uniqueness in db too
  mount_uploader :translation_handwritten, TranslationsUploader
end

Here is my form view:

 =form_tag(:action => 'upload_translation_handwritten', :method => 'post')
   .form-group 
     %label.h4{for: "handwrittenTranslation"} Upload Handwritten Translation
     %input#inputFile{name: 'translation', type: "file"}
     %button.btn.btn-default{type: "submit"} Upload

Here is my uploader:

class TranslationsUploader < CarrierWave::Uploader::Base

  storage :file

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def default_url
    ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
  end

  def extension_white_list
    %w(jpg pdf png)
  end
end

And in my controller I try setting the file:

def upload_translation_handwritten
      @video = Video.find_by_video_id(params[:video_id])
      @video.translation_handwritten = params[:translation]
      @video.save!
      ...
  end

params[:translation] has the correct info from the form. I've confirmed that. When I try printing @video.translation_handwritten.url though, it just comes up with my default path. Does anyone have any suggestions of what to try? I'm obviously very new to carrierwave...

Thank you!!!

Upvotes: 0

Views: 1949

Answers (1)

rakoonise
rakoonise

Reputation: 539

It turned out to be an issue with where I set the file to be saved. I should've been sending it to my public/ directory.

Upvotes: 0

Related Questions