问题描述
我已经为此苦苦挣扎了两个小时.在我的视图中使用carrierwave_direct的direct_upload_form_for
时,它返回此错误:
I've been struggling with this for a couple of hours now. When using carrierwave_direct's direct_upload_form_for
in my view, it returns me this error:
FileUploader Carrierwave类别:
class FileUploader < CarrierWave::Uploader::Base
include CarrierWaveDirect::Uploader
end
手册文件模型:
class ManualFile
include Mongoid::Document
mount_uploader :file, FileUploader
field :name, :type => String
end
UploadController:
class UploadController < ApplicationController
def manual_new
@uploader = ManualFile.new.file
@uploader.success_action_redirect = upload_edit_path
end
def manual_edit
@myfile = ManualFile.new(key: params[:key])
end
end
我的视图:
<%= direct_upload_form_for @uploader do |f| %>
<%= f.file_field :file %>
<%= f.submit %>
<% end %>
我不明白我在做什么错.我尝试遵循此 railscast .我使用的是Ruby 1.9.3,Rails 3.2.3,Mongoid 3,以及载有指向github master的载波的宝石.
I can't understand what I'm doing wrong. I tried to follow this railscast. I'm using Ruby 1.9.3, Rails 3.2.3, Mongoid 3 with carrierwave gems pointing to github master.
推荐答案
显然direct_upload_form_for
与ActiveRecord一起使用效果最佳.为了使其与Mongoid一起使用(或至少不会崩溃),我在文件上传器中添加了以下几行.
Apparently direct_upload_form_for
works best with ActiveRecord. To make it work (or at least not crash) with Mongoid, I added the following lines to my file uploader.
include ActiveModel::Conversion
extend ActiveModel::Naming
所以在您的情况下:
class FileUploader < CarrierWave::Uploader::Base
include CarrierWaveDirect::Uploader
include ActiveModel::Conversion
extend ActiveModel::Naming
end
这篇关于Carrierwave_Direct的direct_upload_form_for返回FileUploader:Class的未定义方法"model_name"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!