1
我剛剛完成創建一個簡單的Carrierwave文件上傳系統(通過例如在http://railscasts.com/episodes/253-carrierwave-file-uploads)Carrierwave執行不工作
這裏是我的模型:
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
這裏是我的表單視圖:
<%= form_for @video.video_id, :html => {:multipart => true} do |f| %>
<p>
<%= f.file_field :translation_handwritten %>
</p>
<p><%= f.submit :Upload %></p>
<% end %>
這是我上傳:
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
但是,每次我嘗試實際上傳時,它都會重定向並正確給出Flash通知,但實際上並未上傳到圖像。當我打印@ video.translation_handwritten.url時,它顯示/assets/fallback/default.png這是我的默認網址。問題在哪裏?我一直盯着這永遠...
謝謝!