0
キャリアウェーブでデータベースに画像をアップロード/保存しようとしています。しかし、私の添付ファイルはDB上で持続されていません。名前フィールドのみがテーブルに格納されます。Carrierwaveファイルのアップロードが機能しない - Nilの値が保存される
私はこのチュートリアルを参照して:http://www.tutorialspoint.com/ruby-on-rails/rails-file-uploading.htm
私は徹底的に研究した後に強いのparamsを変更するには、いくつかの異なる方法を試してみました。
def new
@projectImage = ProjectImage.new
end
def projectImage_params
params.require(:project_image).permit(:name, attachment:[])
#params.require(:project_image).permit(:project_image_attributes=>['name','attachment']) ---- no luck
#params.require(:project_image).permit(:name, :attachment,{}) ------ no luck
end
ビュー
<%= form_for ProjectImage.new, html: { multipart: true } do |image| %>
<h4> <%= image.label :name %>
<%= image.text_field :name %>
</h4>
<h4>
<%= image.label :attachment %>
<%= image.file_field :attachment, multiple: true %>
</h4>
<%= image.submit "Save" %>
<% end %>
パラメータ
Parameters: {"utf8"=>"✓", "authenticity_token"=>"I+Q==", "project_image"=>{"name"=>"Image 3", "attachment"=>[#<ActionDispatch::Http::UploadedFile:0x0000000592c4d0 @tempfile=#<Tempfile:C:/Users/xx/AppData/Local/Temp/RackMultipart20160412-7900-1y69rwv.jpg>, @original_filename="jet.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"project_image[attachment][]\"; filename=\"jet.jpg\"\r\nContent-Type: image/jpeg\r\n">]}, "commit"=>"Save"}
[#<ActionDispatch::Http::UploadedFile:0x0000000592c4d0 @tempfile=#<Tempfile:C:/Users/STUART~1.MIN/AppData/Local/Temp/RackMultipart20160412-7900-1y69rwv.jpg>, @original_filename="jet.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"project_image[attachment][]\"; filename=\"jet.jpg\"\r\nContent-Type: image/jpeg\r\n">]
class ProjectImage < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader
end
012:しかし、何もテーブル
#<ProjectImage id: 6, name: "Image 3", attachment: nil>
ProjectImagesControllerで:(
を働いていませんの
AttachmentUploaderクラス
class AttachmentUploader < CarrierWave::Uploader::Base
storage :file
uploader = AttachmentUploader.new
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
任意の助けが賞賛されるだろう!
乾杯
複数の取り外しを行いました。 – Newbie