Veritabanı içindeki resimleri uploadwave ile karşıya yüklemeye/kaydetmeye çalışıyorum. Ama ekim db'de ısrar etmiyor. sadece isim alanı tabloda saklanır.Carrierwave dosyası yüklenemedi - Nil değeri kaydedildi
Bu öğreticiler atıfta bulundu: Ben ayrıntılı araştırma sonrasında güçlü params değiştirmeye birkaç farklı yol denedim http://www.tutorialspoint.com/ruby-on-rails/rails-file-uploading.htm
.
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
Görünüm
<%= 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 %>
Parametreler
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: Ama hiçbir şey masanın
#<ProjectImage id: 6, name: "Image 3", attachment: nil>
ProjectImagesController On :(
çalıştı
AttachmentUploader sınıf
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
Herhangi bir yardım
hayran olurdu! Şerefe
birden Çıkarma yaptı. – Newbie