0

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
4
  • Remove the validation from presumably Resume
    – j-dexx
    Nov 30, 2016 at 13:08
  • @j-dexx already done, didn't change anything.. Nov 30, 2016 at 13:10
  • In the model? Not just changing required to false.
    – j-dexx
    Nov 30, 2016 at 13:20
  • @j-dexx Yes, in the model. updated my question with the code of my model. Nov 30, 2016 at 13:24

1 Answer 1

1

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

1
  • Thank you, worked! I tried everything... but I didn't thought that it would be so easy. :P Dec 1, 2016 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.