Ruby Rails 回形针协会下拉菜单

Ruby on Rails Paperclip Association Dropdown

我在 RoR 站点中遇到了 Paperclip 的错误。我有一个表单关联控件,Paperclip 中的最大大小设置为 1 MB。当用户打破这个限制时,它会导致关联框只有 Yes 和 No 作为选项,如果用户提交带有新的较小文件的页面,则会导致严重错误。当超过大小时,我已经看到错误报告,但不是这个特定的错误。只要用户在限制内,图片上传就可以正常工作。

型号

class Vehicle < ActiveRecord::Base
  belongs_to :vehicle_location
  has_many :reservations
  has_attached_file :image, styles: { medium: "320x240>", thumb: "32x24>"}
  validates_attachment :image,
                         content_type: { content_type: ['image/jpeg',
                        'image/jpg', 'image/png', 'image/gif'] },
                         size: { less_than: 1.megabytes }
end

class VehicleLocation < ActiveRecord::Base
  has_many :vehicles
end

查看

<%= f.association :vehicle_location, label: false, :collection =>
  @vehicle_locations, :prompt => "Select Location", :wrapper_html => 
  { :style => 'display: inline' } %>

<%= f.file_field :image, label: "Upload an image" %> 

车辆参数值

"vehicle"=>{"unit_number"=>"TEST123", "car_year"=>"2015", "car_make"=>"Ford", "car_model"=>"Test", "vin_number"=>"123456123456", "average_mileage"=>"", "odometer"=>"0", "next_service"=>"3000", "vehicle_location_id"=>"1", "image"=>#ActionDispatch::Http::UploadedFile:0x46f2480 @original_filename="test.JPG", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"vehicle[image]\"; filename=\"test.JPG\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#File:C:/Users/Test~1/AppData/Local/Temp/RackMultipart20150921-460-8hrte0>>, "is_serviced"=>"0", "is_archived"=>"0"}

我也尝试过使用 collection_select,但是当我这样做时出现错误

ActiveRecord::AssociationTypeMismatch in VehiclesController#create

VehicleLocation(#47412924) expected, got String(#19395840).

@vehicle_locations 未在控制器的创建或更新方法中定义(在 new/edit 中)。它给人的印象只是回形针问题,因为回形针拒绝是唯一会触发它的东西。