Tag: 回形针

更智能的回形针validation

我在rails应用程序中使用paperclip,并在我的模型中进行以下三次validation validates_attachment_presence :photo validates_attachment_size :photo, :less_than=>1.megabyte validates_attachment_content_type :photo, :content_type=>[‘image/jpeg’, ‘image/png’, ‘image/gif’] 如果用户忘记添加附件,则所有三个validation都会失败,因此会向用户显示以下三个错误: # Photo file name must be set. # Photo file size file size must be between 0 and 1048576 bytes. # Photo content type is not included in the list 我认为最好只显示此实例中的第一个错误,因为其他两个错误纯粹是后果…我希望用户只有在添加附件但不符合时才会看到后两个错误validation标准。 我确定没有预先出现的validation可以做这种事情,并且通过阅读vendor / plugins / paperclip / lib / paperclip.rb中的代码,我看到validates_attachment_size方法支持:unless参数如下所示: def validates_attachment_presence name, […]

在Heroku上使用Rails 3和paperclip上传多个文件

我需要在我的Rails 3应用程序上使用一个界面将多个文件上传到Amazon S3(因为我在heroku上),可能还有进度条。 我已经轻松管理了如何设置回形针和上传单个文件,但我现在真的迷失了如何继续前进。 请你给我一些建议吗? 这是我在互联网上搜索的2天,但我找不到可行的解决方案 **编辑** 我真的无法理解……我生气了,因为我已经失去了太多时间……请帮助我。 如果我尝试打开Johnny引用的示例应用程序,我只能得到这个(在我的应用程序中它是相同的): 用户界面在哪里? 我的浏览器有什么问题吗? **编辑2 ** 在GitHub上你可以找到我的testapp …请你能解释一下为什么该死的上传用户界面没有出现? 谢谢! **编辑3 ** 非常感谢Johnny,我不知道jquery和原型不能共存的事实。 现在插件正确显示,但尝试上传它创建一个新的“上传”记录,但其附件字段为空,文件不在s3上。 这就是控制台所说的: Started POST “/uploads” for 127.0.0.1 at 2011-06-27 16:17:22 +0200 Processing by UploadsController#create as JSON Parameters: {“utf8″=>”✓”, “authenticity_token”=>”GesRBTiZR1f2LV/bAeAdxWqF++gxcDJw4pPGStYGsH8=”, “upload”=>{“attachment”=>[#<ActionDispatch::Http::UploadedFile:0x000001032834b8 @original_filename="animal-tiger-66550.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"upload[attachment][]\"; filename=\"animal-tiger-66550.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#>]}} AREL (0.5ms) INSERT INTO “uploads” (“attachment”, “created_at”, “updated_at”, […]

导轨:回形针和预览?

你知道在某些网站上你被要求上传一个头像,你点击按钮,选择你的文件,然后点击确定,但在你提交页面之前 (如,没有创建/更新记录),显示图像的一点预览? 如何使用Paperclip for Rails实现这一目标? 对于任何可以指向我的教程或可能告诉我如何在保存记录之前对图像进行Javascript裁剪的人的奖励积分。 我无法在Google上找到关于此主题的更多内容…感谢您的帮助!

我无法安装回形针

我是rails的新手,我需要安装Peperclip( https://github.com/thoughtbot/paperclip ),我不能,我看了我能找到的每个教程,但我找不到错误。 我安装了ImageMagick并遵循github的所有指令。 当我跑: rails generate paperclip club imagen 我懂了 /Users/Moski/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/generators/actions/create_migration.rb:13:in `migration_file_name’: protected method `migration_file_name’ called for # (NoMethodError) from /Users/Moski/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/generators/actions/create_migration.rb:34:in `existing_migration’ from /Users/Moski/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/thor-0.19.1/lib/thor/actions/empty_directory.rb:112:in `invoke_with_conflict_check’ from /Users/Moski/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:60:in `invoke!’ from /Users/Moski/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/thor-0.19.1/lib/thor/actions.rb:94:in `action’ from /Users/Moski/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/generators/migration.rb:36:in `create_migration’ from /Users/Moski/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/railties-4.0.4/lib/rails/generators/migration.rb:65:in `migration_template’ from /Users/Moski/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/paperclip-4.1.1/lib/generators/paperclip/paperclip_generator.rb:16:in `generate_migration’ from /Users/Moski/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run’ from /Users/Moski/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command’ from /Users/Moski/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all’ from /Users/Moski/.rvm/gems/ruby-2.0.0-p451@railstutorial_rails_4_0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each’ […]

Rails 3,paperclip + S3 – 如何存储实例并保护访问权限

我有一个带回形针的Rails 3应用程序,目的是在S3上存储数据。 在应用程序中,用户属于一个实例。 我希望每个实例的所有模型都存储数据。 并且希望阻止来自实例A的用户访问或能够从实例B加载数据。 处理这个问题的最佳方法是什么? 谢谢

如何通过Paperclip rails 4上传图像,文档文档和/或PDF文件

我想让用户将Word文档和PDF文件上传到我的rails应用程序。 我的应用程序类似于Pinterest应用程序,用户可以创建Pins ,它们附加图片后跟描述(使用Paperclip将图像附加到Pin )。 这是我的Pins模型: class Pin { :medium => “300×300>”, :thumb => “100×100>” } validates_attachment :image, content_type: { content_type: [“image/jpg”, “image/jpeg”, “image/png”, “image/gif”] } validates :image, presence: true end 我的Pins控制器: class PinsController params[:page], :per_page => 15) end def show end def new @pin = current_user.pins.build end def edit end def create @pin = current_user.pins.build(pin_params) […]

如何访问使用Paperclip / Ruby on Rails上传的文件的原始内容?

我正在使用Paperclip / S3进行文件上传。 我上传文本类文件(不是.txt,但它们本质上是.txt)。 在show controller中,我希望能够获取上载文件的内容,但不要将内容视为其属性之一。 我能在这做什么? attachment_file_name: “test.md”, attachment_content_type: “application/octet-stream”, attachment_file_size: 58, attachment_updated_at: “2011-06-22 01:01:40” PS – 似乎所有Paperclip教程都是关于图像,而不是文本文件。

Ruby on Rails – Paperclip错误

作为参考,我一直在关注本教程: https : //devcenter.heroku.com/articles/paperclip-s3除了我现在在localhost测试中,所以我安装了Figaro gem并将我的S3信息放在application.yml中。 使用Rails v4,Cocaine v0.5.3和Paperclip v4.1.0(不确定是否需要提及任何其他gem版本号)。 我有一个名为SubmissionDetails的模型,在new.html.erb中我试图将jpg上传到名为attachment的列。 这是相关的型号代码: has_attached_file :attachment, styles: { thumb: ‘200×200>’, large: ‘800×800>’ } validates_attachment_content_type :attachment, content_type: /\Aimage\/.*\Z/ 当我尝试上传jpg时,它返回到表单,并显示以下错误消息: 1 error prohibited this submission_detail from being saved: Attachment translation missing: en.activerecord.errors.models.submission_detail.attributes.attachment.spoofed_media_type 我理解了一些错误,我的en.yml文件中缺少显示此错误消息的文本,但那个欺骗媒体类型部分呢? 这显示在我的服务器控制台中,不确定这是否相关: [paperclip] Content Type Spoof: Filename header.jpg ([“image/jpeg”]), content type discovered from file command: . See documentation […]

Ruby / Paperclip:如何让missing.png工作?

我正在创建用户头像。 我无法显示“missing.png”。 对于决定不上传个人资料照片的用户,我创建了一个默认图像进行显示。 以下是我到目前为止所得到的。 请告诉我我做错了什么。 user.rb has_attached_file :avatar, styles: { large: “800×800>”, medium: “300×300>”, thumb: “50×50>” }, default_url: “/images/:style/missing.png” validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/ posts / index.html.erb (暂时显示所有用户的所有post) users / show.html.erb (这是用户的个人资料页面) “missing.png” 图片: app/assets/images/missing.png 拇指: app/assets/images/thumb/missing.png 中: app/assets/images/medium/missing.png 大: app/assets/images/large/missing.png 我究竟做错了什么?

你能用Paperclip识别图像的当前尺寸吗?

我刚刚更新了图像缩略图的尺寸,并且一直致力于更新28,000个照片对象。 不幸的是,这种过程需要很长时间才能完成。 在这个过程中,一些被拒绝,一些进程被取消。 有没有办法确定图像缩略图是否具有当前尺寸?