通过电子邮件发送zip存档,使用Paperclip发送Rails 4

时间:2016-10-01 20:17:22

标签: ruby-on-rails ruby paperclip actionmailer

网页访问者可以发送带有zip附件的电子邮件。

有一段时间它没有问题,但目前它已不再适用了。当访问者提交表单时,会显示错误消息:

No such file or directory @ rb_sysopen - /home/individualki/blogs/public/system/attachments/units//original/gallery-img2.zip

enter image description here

发送电子邮件没有问题,但没有附件。我认为问题在于附件保存,因为在public \ system \ attach中不是任何新文件。

我搜索了类似的问题,但没有一个具有相同的情况和修复我想要的。

_form.html.erb

<%= form_for(@offer,:html => {"data-parsley-validate" => true, :id=>"offer-create",:multipart => true }) do |f| %> 


        <%= f.email_field :email ,:class=>"user-input form-control", :id=>"password",:required => true,:placeholder=> t('email')%>  


         <div class="uplo-button">
               <li>  <%= file_field_tag "units[]", type: :file, multiple: false,:id=>"u1" %> <div class="cross" id="offer-crosses-1"></div></li>                   
               <li>  <%= file_field_tag "units[]", type: :file, multiple: false,:id=>"u2"%> <div class="cross" id="offer-crosses-2"></div></li>

               <li>  <%= file_field_tag "units[]", type: :file, multiple: false,:id=>"u3"%> <div class="cross" id="offer-crosses-3"></div></li>
            </div>

       <button type="submit" class="blue-button btn btn-default"><%= t('send') %></button>

offer.rb

 has_many :attachments, :dependent => :destroy

Attachment.rb

class Attachment < ActiveRecord::Base


   belongs_to :offer        
      has_attached_file :unit, default_url: "/images/:style/missing.png"
       validates_attachment_content_type :unit, :content_type => [ "application/zip", "application/x-zip", "application/x-zip-compressed", "application/rar", "application/x-rar", "application/x-rar-compressed"]



     before_post_process :skip_for_zip, :skip_for_rar

       def skip_for_zip
         ! %w(application/zip application/x-zip).include?(unit_content_type)
       end


       def skip_for_rar
         ! %w(application/rar application/x-rar).include?(unit_content_type)
       end


end

Offer_controller.rb

     def create

         @offer = Offer.new(offer_params)    

            respond_to do |format|
             if @offer.save

                 if params[:units]

                    params[:units].each { |unit|
                   @offer.attachments.create(unit: unit)
                    }
                 end

              OffereNotifier.send_offer_email(@offer).deliver
               format.html { redirect_to :back, notice: 'Thing was successfully created.' }
               format.json { render json: @offer }
             else
               format.html { render action: 'new' }
               format.json { render json: @offer.errors.full_messages, status: :unprocessable_entity }
             end
          end
     end


  private

    def offer_params
      params.require(:offer).permit(:name,:units, :email, :website, :content, :not_a_robot, :offer_id ,:humanizer_answer, :humanizer_question_id, attachments_attributes: [:unit])
    end

日志:

Started POST "/lv/offers.json" for 85.254.76.36 at 2016-10-01 20:43:19 +0300
    Processing by OffersController#create as JSON
      Parameters: {"utf8"=>"✓", "offer"=>{"name"=>"xxxxxxxxxxxxxxxxx", "email"=>"edgars@gmail.com", "website"=>"wwww.lggl.lv", "content"=>"SDASADAS ASD AS ADS ", "humanizer_question_id"=>"2", "humanizer_answer"=>"10", "not_a_robot"=>"1"}, "remotipart_submitted"=>"true", "authenticity_token"=>"vqi6PlAy8IFqvYSAlZnXjQs1MuN8W9Q5ISHw3qx+cf4=", "X-Requested-With"=>"IFrame", "X-Http-Accept"=>"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01", "units"=>[#<ActionDispatch::Http::UploadedFile:0x0000000567e710 @tempfile=#<Tempfile:/tmp/RackMultipart20161001-961065-1bth2iq>, @original_filename="Rozenfelds-18.03.zip", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"units[]\"; filename=\"Rozenfelds-18.03.zip\"\r\nContent-Type: application/octet-stream\r\n">], "locale"=>"lv"}
      [1m[36mBanlist Load (0.7ms)[0m  [1mSELECT `banlists`.* FROM `banlists`  WHERE (ip_adress = '85.254.76.36')[0m
      [1m[35mCountry Load (0.6ms)[0m  SELECT  `countries`.* FROM `countries`  WHERE `countries`.`id` = 1 LIMIT 1
      [1m[36mRegion Load (0.8ms)[0m  [1mSELECT `regions`.* FROM `regions`  WHERE `regions`.`country_id` = 1[0m
      [1m[35mPartner Load (0.5ms)[0m  SELECT  `partners`.* FROM `partners`  WHERE `partners`.`id` = 1 LIMIT 1
      [1m[36m (0.3ms)[0m  [1mBEGIN[0m
      [1m[35mSQL (193.0ms)[0m  INSERT INTO `offers` (`content`, `created_at`, `email`, `name`, `updated_at`, `website`) VALUES ('SDASADAS ASD AS ADS ', '2016-10-01 20:43:20', 'edgars.rworks@gmail.com', 'xxxxxxxxxxxxxxxxx', '2016-10-01 20:43:20', 'wwww.lggl.lv')
      [1m[36m (0.3ms)[0m  [1mCOMMIT[0m
      [1m[35m (0.4ms)[0m  BEGIN
    Command :: PATH=/usr/bin:$PATH; file -b --mime '/tmp/d378e373c7587977b3ef2bbc8ed18e6b20161001-961065-1hnckc2.zip'
    Command :: PATH=/usr/bin:$PATH; file -b --mime '/tmp/d378e373c7587977b3ef2bbc8ed18e6b20161001-961065-33oai6.zip'
      [1m[36m (0.3ms)[0m  [1mCOMMIT[0m
      [1m[35mAttachment Load (92.8ms)[0m  SELECT `attachments`.* FROM `attachments`  WHERE `attachments`.`offer_id` = 66

    OffereNotifier#send_offer_email: processed outbound mail in 98.8ms
    Completed 500 Internal Server Error in 982ms

    Errno::ENOENT (No such file or directory @ rb_sysopen - /home/individualki/blogs/public/system/attachments/units//original/Rozenfelds-18.03.zip):
      app/mailers/offere_notifier.rb:9:in `read'
      app/mailers/offere_notifier.rb:9:in `block in send_offer_email'
      app/mailers/offere_notifier.rb:8:in `send_offer_email'
      app/controllers/offers_controller.rb:21:in `block in create'
      app/controllers/offers_controller.rb:10:in `create'

0 个答案:

没有答案