Reputation: 539
I've just finished creating a simple Carrierwave file upload system (via the example at http://railscasts.com/episodes/253-carrierwave-file-uploads)
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_for @video.video_id, :html => {:multipart => true} do |f| %>
<p>
<%= f.file_field :translation_handwritten %>
</p>
<p><%= f.submit :Upload %></p>
<% end %>
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
Whenever I try actually uploading, however, it redirects and gives a flash notice appropriately but does not actually upload to image. When I print @video.translation_handwritten.url it shows /assets/fallback/default.png which is my default url. Where might the issue be? I've been staring at this forever...
Thank you!!!
Upvotes: 1
Views: 98
Reputation: 2414
This might not be your only problem, but you need to change
form_for @video.video_id, :html => {:multipart => true} do |f|
to
form_for @video, :html => {:multipart => true} do |f|
If that doesn't fix it, you should post your controller's create
method.
Upvotes: 1