[英]Upload file with carrierwave without name
It's me again. 又是我。 I try to upload some yaml files with carrierwave.
我尝试使用carrierwave上传一些yaml文件。 Everything works fine till now.
到目前为止一切正常。
So, as you know for carrierwave the forms looks like the follow: 因此,如您所知,载波形式如下所示:
<%= form_for @resume, html: { multipart: true } do |f| %>
<%= f.label :name %><br>
<%= f.text_field :name, :required => true %>
<%= f.label :attachment %><br>
<%= f.file_field :attachment, :required => true %>
<br><br>
<%= f.submit "Save", class: "btn btn-primary" %>
<% end %>
What i want to do now is to remove the "name" field. 我现在要做的是删除“名称”字段。 I don't need it.
我不需要 So i thought its quite easy, just remove the "name" part of the form.
因此,我认为它非常容易,只需删除表单的“名称”部分即可。 But then I got an error while upload:
但是后来上传时出现错误:
Name can't be blank
So I tried now nearly everything... I had set the required => false
same result. 因此,我现在几乎尝试了所有操作...我已经设置了
required => false
相同结果。 I went to Github and tooked a look at their how-to... there are methods to overwrite the name, but nobody cares about upload a file without a name. 我去了Github,看了看他们的操作方法...有一些方法可以覆盖名称,但是没有人关心上传没有名称的文件。 May somebody can tell me how i can upload a file without this name field?
有人可以告诉我如何在没有此名称字段的情况下上传文件吗?
Thanks! 谢谢!
Edit: 编辑:
My resume.rb model: 我的resume.rb模型:
class Resume < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader # Tells rails to use this uploader for this model.
end
My AttachmentUploader: 我的AttachmentUploader:
class AttachmentUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(yml)
end
def filename
"something.jpg" if original_filename # This is the part where i'm trying around right now.
end
end
Try to remove column name
on table resumes
and others related, maybe on views, controller ( strong params
), migration file... 尝试删除表
resumes
和其他相关的列name
,例如视图,控制器( strong params
),迁移文件...
Then re-run drop, migrate database 然后重新运行drop,迁移数据库
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.