gpt4 book ai didi

ruby-on-rails - 载波。无法使用 STI 保存文件

转载 作者:行者123 更新时间:2023-12-03 15:49:12 26 4
gpt4 key购买 nike

我有型号 Document :

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(...)或对证书执行相同操作,除了 file 之外,始终保存所有参数。 ,始终是 nil
我也试过挂载 file内部 Document模型...请帮帮我。

这是日志:
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)

谢谢。

最佳答案

您确定您已将用于上传文件的表单设置为具有多部分负载吗?

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

:html => {:multipart => true}

关于ruby-on-rails - 载波。无法使用 STI 保存文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9766565/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com