将PDF / Worddocs上传到应用程序Rails后获取“nil”
因此,我正在构建一个应用程序,用户可以在其中创建Pin并将图片和PDF / Word.docs上传到Pin 。 似乎我已经做了一切来启用这些选项;
在Pins模型中创建的方法:
class Pin { :medium => "300x300>", :thumb => "100x100>" } validates_attachment :image, content_type: { content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"] } validates :image, presence: true has_attached_file :document validates_attachment :document, :content_type => { :content_type => %w(application/pdf application/msword application/vnd.openxmlformats-officedocument.wordprocessingml.document) } end
在DB中生成迁移
class AddFileToPin < ActiveRecord::Migration def self.up change_table :pins do |t| t.attachment :document end end def self.down drop_attached_file :pins, :document end end
然后运行rake db:migrate
为我的架构中的文档添加几行
现在这里是问题(或问题):
我在终端上运行了rails console
,开始看看我创建的一些Pins 。
例如: Pin.find(3)
(查找我创建的第3个Pin ,附带图像和PDF)
这是输出:
Pin Load (0.5ms) SELECT "pins".* FROM "pins" WHERE "pins"."id" = ? LIMIT 1 [["id", 3]] => #
正如您所看到的,PDF的内容是“无”。 所以,我想知道它是否真的得到了保存,如果没有,我该如何解决这个问题呢?