Twinfriends Twinfriends - 1 year ago 73
Ruby Question

Upload file with carrierwave without name

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 %>
<%= 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?



My resume.rb model:

class Resume < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader # Tells rails to use this uploader for this model.


My AttachmentUploader:

class AttachmentUploader < CarrierWave::Uploader::Base
storage :file

def store_dir

def extension_white_list

def filename
"something.jpg" if original_filename # This is the part where i'm trying around right now.


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download