使用Rails 4的CarrierWave,不上传文件,而是在数据库中保存(错误)路径

时间:2015-03-19 04:23:32

标签: ruby-on-rails postgresql carrierwave

我目前使用Rails 4制作网络应用程序,我需要上传一些文件。

我使用了carrierwave,但是当我上传文件时,我的数据库中有一些数据(/ home / mathieu / portfolio_memoire / public / uploads / answer / document / 89 / {}作为当前路径,。 ..)但是当我去这个地方.......没有文件,没有文件夹上传.....没有。

以下是我的代码的主要部分:

在我的控制器中:

@answer = Answer.new(:submission_id => @submission.id, :contents => params["upload_#{indice}"],:document => params["upload_#{indice}"])
@answer.save

在我的模特中:

class Answer < ActiveRecord::Base
  belongs_to :submission
  has_many :documents
  mount_uploader :document, DocumentUploader
end

在我的迁移中(我使用postgreSQL数据库):

add_column :answers, :document, :string,array: true, default: '{}'

在我看来:

<%=file_field_tag("upload_#{compteur}", multiple: true)%>

在我的document_uploader.rb中:

require 'carrierwave/orm/activerecord'
class DocumentUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick
  storage :file
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
  def extension_white_list
    %w(jpg jpeg gif png pdf xml doc docx)
  end
  process :set_content_type
end

如果你有想法......

0 个答案:

没有答案