1

I am using paperclip gem to allow users to upload their resumes , the problem is once the user clicks on upload . As mentioned in some tutorials , i set the paperclip env so that it gets the path in development , still it doesn't gets uploaded.

#Error that gets showed on browser 
RuntimeError in ProfilesController#update_resume

#profilescontroller#update_resume
def update_resume
    update! :notice => "Resume successfully updated!" do |success, failure|
      success.html {
          if !@user.section_layout.nil?
            ResumeSection.delete_all "user_id = #{@user.id}"
            @user.section_layout.each {|key,value|
              rs = ResumeSection.new(:section_name => key.encode("UTF-8"), :html => value.encode("UTF-8"), :user => @user)
              rs.save
            }
            redirect_to profile_path
          end
      }
      failure.html { render :template => "/profiles/edit/resume" }
    end
  end


#These are the logs after
Started POST "/profile/update_resume" for 127.0.0.1 at 2014-02-22 17:36:18 +0530
  Processing by ProfilesController#update_resume as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"zRlPQPI88Eqgko5UUdR2YUvmMHsjSDKS0sqOOj2kTu0=", "user"=>{"rb_resume"=>#<ActionDispatch::Http::UploadedFile:0xaef29b4 @original_filename="resume .odt", @content_type="application/vnd.oasis.opendocument.text", @headers="Content-Disposition: form-data; name=\"user[rb_resume]\"; filename=\"resume .odt\"\r\nContent-Type: application/vnd.oasis.opendocument.text\r\n", @tempfile=#<File:/tmp/RackMultipart20140222-16462-1mvioqy>>}, "commit"=>"Update Resume"}
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 11 LIMIT 1
  SQL (0.2ms)  BEGIN
Command :: file -b --mime-type '/tmp/a495763e62ffd9dac862588d08a1ed5420140222-16462-6djcd4'
  SQL (0.1ms)  ROLLBACK
Completed   in 69ms

RuntimeError (Input file needs to be pdf or word format):
  lib/resume/resume_builder.rb:81:in `convert_to_html'
  lib/resume/resume_builder.rb:17:in `initialize'
  lib/paperclip/resume_builder.rb:10:in `new'
  lib/paperclip/resume_builder.rb:10:in `make'
  app/controllers/profiles_controller.rb:51:in `update_resume'

Rendered /usr/local/rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.0.6/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.9ms)
Rendered /usr/local/rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.0.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (257.7ms)
Rendered /usr/local/rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.0.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (264.2ms)

Update - Application Trace

lib/resume/resume_builder.rb:81:in `convert_to_html'
lib/resume/resume_builder.rb:17:in `initialize'
lib/paperclip/resume_builder.rb:10:in `new'
lib/paperclip/resume_builder.rb:10:in `make'
app/controllers/profiles_controller.rb:51:in `update_resume'

Any suggestions regarding doing it correctly are most welcome :)

Caffeine Coder
  • 1,869
  • 1
  • 17
  • 35

1 Answers1

1

Error

Here's your problem -

RuntimeError (Input file needs to be pdf or word format)

I believe this line is the problem:

ResumeSection.new(:section_name => key.encode("UTF-8"), :html => value.encode("UTF-8"), :user => @user)

Validation

I'd ensure Paperclip only allows type validation of Word or PDF:

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

If you do this, can you let us know what happens?

Community
  • 1
  • 1
Richard Peck
  • 76,116
  • 9
  • 93
  • 147