레일 및 캐리어 웨이브를 사용하여 이미지를 mongodb에 업로드하는 데 문제가 있습니다. 이것은 내가 무엇입니까 오류 메시지입니다레일, 캐리어 웨이브 및 몽고이드로 이미지 업로드 문제
Cannot serialize an object of class ActionDispatch::Http::UploadedFile into BSON.
내 모델이
class Offer
include Mongoid::Document
include Mongoid::Timestamps
field :name, :type => String
field :desc, :type => String
field :expiry, :type => Date
has_one :image, as: :viewable
embeds_many :locations, as: :locatable
end
및
class Image
include Mongoid::Document
include Mongoid::Timestamps
field :name, :type => String
field :extension, :type => String
mount_uploader :image, ImageUploader
belongs_to :viewable, polymorphic: true
end
처럼 보인다 그리고보기
<%= nested_form_for @offer, :html => {:method => :post, :id => "offerNew", :class => "uniForm", :multipart => true} do |f| %>
<fieldset class="inlineLabels" id="setBiz">
<div class="ctrlHolder">
<%= f.label :name, mark_mandatory("Offer Name") %>
<%= f.text_field :name, :class => "textInput large" %>
<p class="formHint">Name of the offer to be displayed in ads ex:5% offer on Panasonic vierra LCD </p>
</div>
<div class="ctrlHolder">
<%= f.label :image, "Image" %>
<%= f.file_field :image %>
<p class="formHint">Upload image </p>
</div>
</fieldset>
<% end %>
입니다 이들은
"utf8"=>"✓",
"authenticity_token"=>"8GhVGBg2zTI9FQwZmnKiZtBmgM5DiaQmPZaUIhNeF6I=",
"offer"=>{"catid"=>"4e590231b356f8015f000030",
"name"=>"aaaaaaaaaaaaaaaaaaaa",
"expiry"=>"22/09/2011",
"image"=>#<ActionDispatch::Http::UploadedFile:0xb412e30 @original_filename="51MF4101AA000.jpg",
@content_type="image/jpeg",
@headers="Content-Disposition: form-data; name=\"offer[image]\"; filename=\"51MF4101AA000.jpg\"\r\nContent-Type: image/jpeg\r\n",
@tempfile=#<File:/tmp/RackMultipart20110908-2893-1a8yqe2>>,
"loc"=>[80.22167450000006,
13.0454044],
}}
을 컨트롤러로 전송되는 매개 변수입니다하지만 난 수동으로 내가 carrierwave이 파일 처리 돌볼 것이라고 생각이
params[:images].each do |img|
image = Image.new(:extension => img.content_type.split('/')[1])
image.image = img
@business.images << image
end
같은 이미지 문서를 만들 곳은 또 다른 형태로 잘 작동했지만, 나는 무엇이 놓치고 있는지 확신 할 수 없다?
옳아 .. 고마워. – RameshVel