Reputation: 1987
It's me again. I try to upload some yaml files with carrierwave. 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.
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. May somebody can tell me how i can upload a file without this name field?
Thanks!
Edit:
My resume.rb model:
class Resume < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader # Tells rails to use this uploader for this model.
end
My 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
Upvotes: 0
Views: 413
Reputation: 543
Try to remove column name
on table resumes
and others related,
maybe on views, controller (strong params
), migration file...
Then re-run drop, migrate database
Upvotes: 1