2012-03-19 74 views
4

我有模型DocumentCarrierWave。无法保存文件STI

class Document < ActiveRecord::Base 
    belongs_to :company 
    validates :name, :presence => true 
end 

两班从Document继承:

License

class License < Document 
    mount_uploader :file, DocumentUploader 
end 

而且Certificate

class Certificate < Document 
    mount_uploader :file, DocumentUploader 
end 

,当我尝试做current_company.licenses.create(...)或证书同样的动作,总是所有PARAMS被保存,除了file,这总是nil

而且我试着安装fileDocument模型里面......请帮助我。

下面是日志:

Started POST "/companies/1/verified" for 127.0.0.1 at Mon Mar 19 09:33:41 +0200 2012 
Processing by CompaniesController#verified as HTML 
    Parameters: {"verified"=>{"certificate"=>{"name"=>"Certificate", "file"=>"test.png"}, "insured"=>"2000000", "suppliers"=>"", "license"=>{"name"=>"License", "file"=>"test.png"}}, "authenticity_token"=>"0hIn41Tjonm/AXZBKM1PE/tjQxJDLqZaojMTHDoZq2k=", "id"=>"1", "utf8"=>"✓", "commit"=>"Update verifications"} 
    Company Load (0.7ms) SELECT "companies".* FROM "companies" WHERE "companies"."id" = 1 LIMIT 1 
    (0.1ms) BEGIN 
    SQL (0.8ms) INSERT INTO "documents" ("company_id", "created_at", "file", "name", "type", "updated_at", "verified") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["company_id", 1], ["created_at", Mon, 19 Mar 2012 07:33:41 UTC +00:00], ["file", nil], ["name", "License"], ["type", "License"], ["updated_at", Mon, 19 Mar 2012 07:33:41 UTC +00:00], ["verified", false]] 
    (0.6ms) COMMIT 
    (0.1ms) BEGIN 
    SQL (0.5ms) INSERT INTO "documents" ("company_id", "created_at", "file", "name", "type", "updated_at", "verified") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["company_id", 1], ["created_at", Mon, 19 Mar 2012 07:33:41 UTC +00:00], ["file", nil], ["name", "Certificate"], ["type", "Certificate"], ["updated_at", Mon, 19 Mar 2012 07:33:41 UTC +00:00], ["verified", false]] 
    (0.4ms) COMMIT 
Redirected to http://localhost:3000/company/profile 
Completed 302 Found in 18ms (ActiveRecord: 3.3ms) 

感谢。

+0

的[CarrierWave保存在文件中的列NULL]可能重复[1] [1]:http://stackoverflow.com/questions/9134339/carrierwave-save-null-at-文件列 – 2012-03-30 07:14:41

回答

1

你确定你已经设置了你上传文件的窗体来拥有多部分有效载荷吗?

如果不是在提交时不会发送文件,并且rails将只接收文本表单数据。在form_helper标签内,您需要添加。

:html => {:multipart => true}