简体   繁体   English

在Rails中,如何通过回形针将上传的文件(图像或pdf)保存到数据库?

[英]In rails, how to save uploaded files (image or pdf) through paperclip to database?

As I am newbie to the rails, I am not sure how to save the files (pdf/image) to the database in the rails. 由于我是Rails的新手,所以我不确定如何将文件(pdf / image)保存到Rails的数据库中。 I am able to upload the image and save it locally and the image info gets save in the database..but I want to save the whole file or image in the database. 我可以上传图像并将其保存在本地,图像信息也保存在数据库中。但是我想将整个文件或图像保存在数据库中。 Your suggestion will be greatly appreciated! 您的建议将不胜感激!

Thanks! 谢谢!

Source: https://github.com/softace/paperclip_database 资料来源: https : //github.com/softace/paperclip_database

gem "paperclip_database", "~> 2.0" 宝石“ paperclip_database”,“〜> 2.0”

class User < ActiveRecord::Base
  has_attached_file :avatar,
                    :storage => :database ## This is the essence
                    :styles => { :medium => "300x300>", :thumb => "100x100>" }
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM