使用PaperClip和Ruby on Rails无限日志

时间:2015-07-17 23:22:37

标签: ruby-on-rails ruby-on-rails-4 paperclip

当我上传文件时,我遇到了一个非常奇怪的问题,我在官方git页面上发布了我的错误/问题:https://github.com/thoughtbot/paperclip/issues/1938

只要按下表单的提交按钮,我就会在我启动rail server的控制台中获得5分钟的日志循环。

这是我的模型

class Ship < ActiveRecord::Base
    belongs_to :user
    has_many :users, through: :votes
    has_many :users, through: :comments

    has_attached_file :shipimage, 
    #:styles => { :thumb=> "100x100#", :small  => ["150x150>", :jpg] },
    :default_url => "/images/shipimages/missing_:style.png",
    :url => "/images/shipimages/:id_:style_:basename.:extension"
    #validates_attachment_presence :shipimage
    validates_attachment_content_type :shipimage,
    :content_type => [
            "image/jpg",
            "image/jpeg",
            "image/png"
        ]
    # validates_attachment :image, presence: true,
    # content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'] },
    # size: { less_than: 5.megabytes }
    has_attached_file :shipfile,
    :url => "/ships/:id_:basename.:extension"
    #validates_attachment_presence :shipfile
    validates_attachment_file_name :shipfile, 
    :matches => [/lua\Z/]

end

这是我的数据库

class CreateShips < ActiveRecord::Migration
  def change
    create_table :ships do |t|

      t.string :name
      t.integer :points

      t.attachment :shipimage
      t.attachment :shipfile

      t.references :user
      t.timestamps
   end
 end
end

这是我的控制器

class ShipsController < ApplicationController

    before_action :require_user, only: [:new, :create]
    before_action :require_admin, only: [:delete, :update]

    def index
        @ships = Ship.all
    end

    def show
        @ship = Ship.find(params[:id])
    end

    def new
        @ship = Ship.new
    end

    def create 
        @ship = Ship.new(ship_params)
        @ship.user = current_user

        if @ship.save
            redirect_to(:action => 'show', :id => @ship.id)
        else 
            render 'new' 
        end 
    end

    def destroy
        @ship = Ship.find(params[:id])
        @ship.destroy
        redirect_to '/'#root_url
    end 

    private 
    def ship_params 
        params.require(:ship).permit(:name, :points, :shipimage, :shipfile) 
    end
end

此处我的观点

<div class="ship_new">
    <div class="form">
        <h1>Upload ship</h1>

        <%= form_for @ship, :html => { :multipart => true } do |f| %>
        <p><%= f.text_field :name, :placeholder => "Name" %></p>
        <p><%= f.number_field :points, :placeholder => "Points" %></p>

        <p><%= f.label :shipimage , "Image" %> <%= f.file_field :shipimage %></p>
        <p><%= f.label :shipfile , "Ship file" %> <%= f.file_field :shipfile %></p>

        <p><%= f.submit "Upload Ship", class: "btn-submit" %></p>
        <% end %>
    </div>
</div>

日志

lication/cybercash", @raw_media_type="application", @raw_sub_type="cybercash", @simplified="application/cybercash", @i18n_key="application.cybercash", @media_type="application", @sub_type="cybercash", @extensions=[]>], "application/dash+xml"=>[#<MIME::Type::Columnar:0x359d300 @container=#<MIME::Type s:0x36d7d48 ...>, @content_type="application/dash+xml", @raw_media_type="application", @raw_sub_type="dash+xml", @simplified="application/dash+xml", @ i18n_key="application.dash-xml", @media_type="application", @sub_type="dash+xml", @extensions=[]>], "application/dashdelta"=>[#<MIME::Type::Columnar:0 x3596aa8 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="application/dashdelta", @raw_media_type="application", @raw_sub_type="dashdelta", @si mplified="application/dashdelta", @i18n_key="application.dashdelta", @media_type="application", @sub_type="dashdelta", @extensions=[]>], "application/ davmount+xml"=>[#<MIME::Type::Columnar:0x3594fc0 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="application/davmount+xml", @raw_media_type="a pplication", @raw_sub_type="davmount+xml", @simplified="application/davmount+xml", @i18n_key="application.davmount-xml", @media_type="application", @s ub_type="davmount+xml", @extensions=["davmount"]>], "application/dca-rft"=>[#<MIME::Type::Columnar:0x35944f8 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="application/dca-rft", @raw_media_type="application", @raw_sub_type="dca-rft", @simplified="application/dca-rft", @i18n_key="application .dca-rft", @media_type="application", @sub_type="dca-rft", @extensions=[]>], "application/dcd"=>[#<MIME::Type::Columnar:0x358fc50 @container=#<MIME::T ypes:0x36d7d48 ...>, @content_type="application/DCD", @raw_media_type="application", @raw_sub_type="DCD", @simplified="application/dcd", @i18n_key="ap plication.dcd", @media_type="application", @sub_type="dcd", @extensions=[]>], "application/dec-dx"=>[#<MIME::Type::Columnar:0x358f5f0 @container=#<MIM E::Types:0x36d7d48 ...>, @content_type="application/dec-dx", @raw_media_type="application", @raw_sub_type="dec-dx", @simplified="application/dec-dx", @i18n_key="application.dec-dx", @media_type="application", @sub_type="dec-dx", @extensions=[]>], "application/dialog-info+xml"=>[#<MIME::Type::Columna r:0x358ee70 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="application/dialog-info+xml", @raw_media_type="application", @raw_sub_type="dialog -info+xml", @simplified="application/dialog-info+xml", @i18n_key="application.dialog-info-xml", @media_type="application", @sub_type="dialog-info+xml" , @extensions=[]>], "application/dicom"=>[#<MIME::Type::Columnar:0x358e7e0 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="application/dicom", @raw_media_type="application", @raw_sub_type="dicom", @simplified="application/dicom", @i18n_key="application.dicom", @media_type="application", @sub _type="dicom", @extensions=["dcm"]>], "application/dii"=>[#<MIME::Type::Columnar:0x358da30 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="app lication/DII", @raw_media_type="application", @raw_sub_type="DII", @simplified="application/dii", @i18n_key="application.dii", @media_type="applicatio n", @sub_type="dii", @extensions=[]>], "application/dit"=>[#<MIME::Type::Columnar:0x358ce30 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="ap plication/DIT", @raw_media_type="application", @raw_sub_type="DIT", @simplified="application/dit", @i18n_key="application.dit", @media_type="applicati on", @sub_type="dit", @extensions=[]>], "application/dns"=>[#<MIME::Type::Columnar:0x358c428 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="a pplication/dns", @raw_media_type="application", @raw_sub_type="dns", @simplified="application/dns", @i18n_key="application.dns", @media_type="applicat ion", @sub_type="dns", @extensions=[]>], "application/docbook+xml"=>[#<MIME::Type::Columnar:0x3587c58 @container=#<MIME::Types:0x36d7d48 ...>, @conten t_type="application/docbook+xml", @raw_media_type="application", @raw_sub_type="docbook+xml", @simplified="application/docbook+xml", @i18n_key="applic ation.docbook-xml", @media_type="application", @sub_type="docbook+xml", @extensions=["dbk"]>], "application/drafting"=>[#<MIME::Type::Columnar:0x3586a 58 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="application/drafting", @raw_media_type="application", @raw_sub_type="drafting", @simplified ="application/drafting", @i18n_key="application.drafting", @media_type="application", @sub_type="drafting", @extensions=[]>, #<MIME::Type::Columnar:0x 48e0d60 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="application/x-drafting", @raw_media_type="application", @raw_sub_type="x-drafting", @s implified="application/drafting", @i18n_key="application.drafting", @media_type="application", @sub_type="drafting", @extensions=[]>], "application/ds kpp+xml"=>[#<MIME::Type::Columnar:0x3585ab0 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="application/dskpp+xml", @raw_media_type="applicati on", @raw_sub_type="dskpp+xml", @simplified="application/dskpp+xml", @i18n_key="application.dskpp-xml", @media_type="application", @sub_type="dskpp+xm l", @extensions=[]>], "application/dssc+der"=>[#<MIME::Type::Columnar:0x3584ec8 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="application/ds sc+der", @raw_media_type="application", @raw_sub_type="dssc+der", @simplified="application/dssc+der", @i18n_key="application.dssc-der", @media_type="a pplication", @sub_type="dssc+der", @extensions=["dssc"]>], "application/dssc+xml"=>[#<MIME::Type::Columnar:0x35841f0 @container=#<MIME::Types:0x36d7d4 8 ...>, @content_type="application/dssc+xml", @raw_media_type="application", @raw_sub_type="dssc+xml", @simplified="application/dssc+xml", @i18n_key=" application.dssc-xml", @media_type="application", @sub_type="dssc+xml", @extensions=["xdssc"]>], "application/dvcs"=>[#<MIME::Type::Columnar:0x3577818 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="application/dvcs", @raw_media_type="application", @raw_sub_type="dvcs", @simplified="applicat ion/dvcs", @i18n_key="application.dvcs", @media_type="application", @sub_type="dvcs", @extensions=[]>], "application/dxf"=>[#<MIME::Type::Columnar:0x3 576648 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="application/dxf", @raw_media_type="application", @raw_sub_type="dxf", @simplified="appl ication/dxf", @i18n_key="application.dxf", @media_type="application", @sub_type="dxf", @extensions=[]>, #<MIME::Type::Columnar:0x48eb410 @container=#< MIME::Types:0x36d7d48 ...>, @content_type="application/x-dxf", @raw_media_type="application", @raw_sub_type="x-dxf", @simplified="application/dxf", @i 18n_key="application.dxf", @media_type="application", @sub_type="dxf", @extensions=[]>], "application/ecmascript"=>[#<MIME::Type::Columnar:0x3574470 @ container=#<MIME::Types:0x36d7d48 ...>, @content_type="application/ecmascript", @raw_media_type="application", @raw_sub_type="ecmascript", @simplified ="application/ecmascript", @i18n_key="application.ecmascript", @media_type="application", @sub_type="ecmascript", @extensions=["ecma"]>], "application /edi-consent"=>[#<MIME::Type::Columnar:0x356b608 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="application/EDI-consent", @raw_media_type="ap plication", @raw_sub_type="EDI-consent", @simplified="application/edi-consent", @i18n_key="application.edi-consent", @media_type="application", @sub_t ype="edi-consent", @extensions=[]>], "application/edi-x12"=>[#<MIME::Type::Columnar:0x356a450 @container=#<MIME::Types:0x36d7d48 ...>, @content_type="

我在我的控制台中获取页面和页面,我启动了rails服务器,它在几分钟后停止。无论我上传哪个文件,都会发生这种情况......

这是日志的结尾ed="video/smv", @i18n_key="video.smv", @media_type="video", @sub_type="smv", @extensions=["smv"]>, #<MIME::Type::Columnar:0x4b03480 @container=#<MIME: :Types:0x4a32d70 ...>, @content_type="x-chemical/x-pdb", @raw_media_type="x-chemical", @raw_sub_type="x-pdb", @simplified="chemical/pdb", @i18n_key="c hemical.pdb", @media_type="chemical", @sub_type="pdb", @extensions=["pdb"]>, #<MIME::Type::Columnar:0x4b02c88 @container=#<MIME::Types:0x4a32d70 ...>, @content_type="x-chemical/x-xyz", @raw_media_type="x-chemical", @raw_sub_type="x-xyz", @simplified="chemical/xyz", @i18n_key="chemical.xyz", @media_t ype="chemical", @sub_type="xyz", @extensions=["xyz"]>, #<MIME::Type::Columnar:0x4b024a8 @container=#<MIME::Types:0x4a32d70 ...>, @content_type="x-conf erence/x-cooltalk", @raw_media_type="x-conference", @raw_sub_type="x-cooltalk", @simplified="conference/cooltalk", @i18n_key="conference.cooltalk", @m edia_type="conference", @sub_type="cooltalk", @extensions=["ice"]>, #<MIME::Type::Columnar:0x4b01cc8 @container=#<MIME::Types:0x4a32d70 ...>, @content _type="x-drawing/dwf", @raw_media_type="x-drawing", @raw_sub_type="dwf", @simplified="drawing/dwf", @i18n_key="drawing.dwf", @media_type="drawing", @s ub_type="dwf", @extensions=["dwf"]>, #<MIME::Type::Columnar:0x4b01608 @container=#<MIME::Types:0x4a32d70 ...>, @content_type="x-world/x-vrml", @raw_me dia_type="x-world", @raw_sub_type="x-vrml", @simplified="world/vrml", @i18n_key="world.vrml", @media_type="world", @sub_type="vrml", @extensions=["wrl ", "vrml"]>], @__attributes__=["content_type"], @__root__="C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/mime-types-2.6.1/data">, @content_type ="image/jpeg", @raw_media_type="image", @raw_sub_type="jpeg", @simplified="image/jpeg", @i18n_key="image.jpeg", @media_type="image", @sub_type="jpeg", @extensions=["jpeg", "jpg", "jpe"]>] from Extension), content type discovered from file command: . See documentation to allow this combination. Command :: file -b --mime "C:/Users/LeoMAC/AppData/Local/Temp/08f1277d6726f4c49e8f176e8eaab93020150717-10948-1bnslyr.lua" [paperclip] Content Type Spoof: Filename Reassembly_Wonay_-_F1_T2_V3_Wonay_20150602_09.34.45.AM__7999P_.lua (application/octet-stream from Headers, [] from Extension), content type discovered from file command: . See documentation to allow this combination. (0.0ms) rollback transaction Rendered ships/new.html.erb within layouts/application (1.0ms) User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]] CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]] Completed 200 OK in 313758ms (Views: 93.0ms | ActiveRecord: 2.0ms) 谢谢!

1 个答案:

答案 0 :(得分:0)

我有一个非常类似的错误,结果发现我只是错过了安装早期版本的回形针所不需要的Windows文件命令。说明可以在这里找到: https://github.com/thoughtbot/paperclip#file