我有一个rails应用程序最初使用Paperclip进行文件上传,但是,当我看到CarrierWave显然在表格重新显示时有一个“持久上传”类型功能时,我决定尝试一下.
在我看来,我有以下几点:
= f.input :attachment = f.hidden_field :attachment_cache
如果表单验证失败并重新显示,则正确缓存文件,但是当我更正验证错误并重新提交时,不会处理附件.
Started POST "/section/model" for 127.0.0.1 at 2012-03-20 08:51:56 +0000 Processing by Client::WishesController#create as HTML Parameters: {"utf8"=>"✓","authenticity_token"=>"zkdPQBsAnsNzx555rkwZ5+clfnLaXg+NtL+GdFei188=","model"=>{"title"=>"Sample","content"=>"Sample content","contact_name"=>"Mr Sample","contact_email"=>"sample@example.com","attachment_cache"=>"20120320-0851-42559-1644/SampleAttachment.pdf"},"commit"=>"Create Wish"} Client Load (0.3ms) SELECT `clients`.* FROM `clients` WHERE `clients`.`id` = 1 LIMIT 1 (0.2ms) BEGIN sql (0.4ms) INSERT INTO `models` (`attachment`,`client_id`,`contact_email`,`contact_name`,`content`,`created_at`,`status`,`title`,`updated_at`,`upload_content_type`,`upload_file_name`,`upload_file_size`,`upload_updated_at`) VALUES (NULL,1,'sample@example.com','Mr Sample','Sample content','2012-03-20 08:51:56','Unresolved','Sample',NULL,NULL)
它似乎是通过params中的attachment_cache正确传递附件,但它没有保存附件,因为它没有params [:model] [:attachment]字段.
它没有说明在载波部分上的任何进一步的步骤,使得上传在CarrierWave GitHub上的表格重新显示中起作用.