CarrierWave. Unable to save file with STI

I have a Document model:

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

And two classes inherited from Document :

License :

 class License < Document mount_uploader :file, DocumentUploader end 

And Certificate

 class Certificate < Document mount_uploader :file, DocumentUploader end 

And when I try to do current_company.licenses.create(...) or the same action for the certificate, all parameters are always saved except for file , which is always nil

Also I tried to install file inside the Document model ... Help me please.

Here are the logs:

 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) 

Thanks.

+4
source share
1 answer

Are you sure you installed the form you downloaded to have a multi-page payload?

If the file is not sent when sending, and the rails will receive only text data. Inside the form_helper tag you need to add.

 :html => {:multipart => true} 
+1
source

Source: https://habr.com/ru/post/1402184/


All Articles