1

i am working on rails with paperclip gem and trying to upload a document ,

this is my html form

<div style="background: #ee6e73; width: 100%;"><h3 class="center-align" style="color: #fff;font-weight: 600 !important;">Upload Resume</h3></div>
<div class="modal-content">
  <%= form_for(Document.new, :url => resume_upload_individual_profile_path, remote: true, :html => {:multipart => true } ) do |f| %>
      <%= hidden_field_tag :authenticity_token, form_authenticity_token %>
      <%= hidden_field_tag :profile_id, @profile.id %>
      <div class="row">

        <div class="file-field input-field">
          <div class="btn">
            <span>Choose Document</span>
            <i class="material-icons prefix">input</i>
            <%= file_field_tag :document %>
          </div>
          <div class="file-path-wrapper">
            <input class="file-path validate" type="text">
          </div>
        </div>

      </div>

      </div>
      <div class="modal-footer">
        <button type="submit" style="float: left;margin-top: 0%;" class="waves-effect waves-light btn-large  "><i class="material-icons left">cloud</i>Submit</button>
        <a href="#!" class=" modal-action modal-close waves-effect waves-green btn-flat">Close</a>
      </div>
  <% end %>

and my controller action is

def resume_upload

    p params
    @resume = Document.create(resume_params)
    if @resume.save
      @message = 'Your Resume has been successfully uploaded'
      # redirect_to individual_profile_path(individual_id: current_individual.id)
    else

      # redirect_to individual_profile_path(individual_id: current_individual.id)
      @message = find_error(@resume)
    end
    respond_to do |format|
      format.js
    end

  end

and my model has

has_attached_file :document
  validates_presence_of :document
  validates_attachment_content_type :document, :content_type => ["application/pdf","application/vnd.ms-excel",
                                                                 "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                                                                 "application/msword",
                                                                 "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
                                                                 "text/plain"] 

the issue i am facing is when i select a file and try to uplaod , i get an error ActionController::UnknownFormat

but I am not facing this issue when i submit the form without selecting the file , i am able to successfully go into the js.erb file.

this is the console error

user4965201
  • 973
  • 1
  • 11
  • 25

1 Answers1

0

In order to get it working with these files you need to add the mime types to the server config. In Rails this is done in config/initializers/mime_types.rb

Mime::Type.register "application/vnd.openxmlformats-officedocument.wordprocessingml.document", :docx

This will help:- What is a correct mime type for docx, pptx etc?

Community
  • 1
  • 1
Malware Skiddie
  • 318
  • 2
  • 12
  • Then maybe you should post more logs to help us understand better. – Malware Skiddie Feb 22 '16 at 08:09
  • Rails has several Mime:Type that are built in. by looking at your logs it's clearly a issue of mime type, your filename states card.png but you don't have validates attachment for images :- validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/ . If it solved your query then mark answer as accepted. – Malware Skiddie Feb 22 '16 at 10:01
  • but i dont want .png to be uploaded . i only want pdf and docs to be uploaded . i tried to upload that .png file so that i could get the validation error mesage – user4965201 Feb 22 '16 at 10:06