Tag: paperclip

我可以使用Paperclip在rails中发表评论吗?

我希望用户能够使用Paperclip支持的图像或gif评论post。 我怎样才能实现这一目标? 它可以与acts_as_commentable一起使用吗?

rails 3.2在编辑操作上跳过回形针附件存在validation

我是Rails的新手,我正在开发第一个使用paperclip作为附件的rails应用程序,我正在使用validates_attachment :avatar, presence: true附件的存在validates_attachment :avatar, presence: true这对创建操作非常有效,但是当用户使用时正在编辑他的帐户设置并且没有上传新的头像,没有上传头像的错误但我想在编辑时跳过该validation并且仅在编辑时validation如果用户上传新的替换现有的那个。 我也有 validates_format_of :avatar, :with => %r{\.(jpg|jpeg|gif|png)$}i,:unless => Proc.new {|m| m[:avatar].nil?}, :message => “Please upload files with the following extensions only 检查格式只有在存在但似乎没有工作时,你的帮助将非常感激。 谢谢

使用FactoryGirl时,Paperclip :: Attachment作为字符串传递

我正在尝试使用FactoryGirl 3.0在rails 3.2.6上创建回形针3.1.2的function测试,当我传递文件附件时,我的控制器接收一个字符串,它是文件位置而不是Paperclip :: Attachment对象。 我的工厂是: include ActionDispatch::TestProcess FactoryGirl.define do factory :artist do id 1 name ‘MyString’ photo {fixture_file_upload(“#{Rails.root}/test/fixtures/files/rails.png”,’image/png’)} end end 我的测试是: test “should create artist” do assert_difference(‘Artist.count’) do post :create, :artist => { name: @artist.name, photo: @artist.photo }, :html => { :multipart => true } end assert_redirected_to artist_path(assigns(:artist)) end 在我的控制器中: params[:artist][:photo].class.name 等于“字符串”,但是当我将它添加到测试时,这会通过 assert @artist.photo.class.name […]

无法弄清楚是什么导致我的测试失败

我是rails的新手,我在没有做TDD的情况下构建了一个应用程序,但我现在回去试图通过所有测试。 我已经通过了他们中的大多数,但还有一些与我无法弄清楚的相同问题有关。 该应用程序也正常运行,我只是无法通过这些测试。 测试失败并提供: 1) ProductsController POST create with valid params assigns a newly created product as @product Failure/Error: post :create, {:product => valid_attributes}, valid_session Paperclip::AdapterRegistry::NoHandlerError: No handler found for “#” # ./app/controllers/products_controller.rb:43:in `new’ # ./app/controllers/products_controller.rb:43:in `create’ # ./spec/controllers/products_controller_spec.rb:86:in `block (4 levels) in ‘ 2) ProductsController POST create with valid params creates a new Product […]

S3直接上传不上传文件

/config/intilializers/paperclip.rb Paperclip::Attachment.default_options[:storage] = :s3 Paperclip::Attachment.default_options[:bucket] = ‘xxx’ Paperclip::Attachment.default_options[:s3_permissions] = :public_read Paperclip::Attachment.default_options[:s3_credentials] = { access_key_id: ‘xxx’ ,secret_access_key: ‘xxx’} /config/intilializers/s3_direct_upload.rb S3DirectUpload.config do |c| c.access_key_id = ‘xx’ # your access key id c.secret_access_key = ‘xxx’ c.bucket = ‘xxx’ # your bucket name c.region = ‘s3-ap-southeast-1’ end AWS.config({ :access_key_id => ‘xxx’, :secret_access_key => ‘xxx’, :region => ‘ap-southeast-1’ }) Ad.rb […]

如何改善里面的Rails / Paperclip图像压缩或ImageMagick / Rmagick?

我正在使用Paperclip在rails中裁剪图像。 我使用这些转换选项: “-quality #{attachment.quality} \ -crop #{attachment.width}x#{attachment.height}+#{attachment.x}+#{attachment.y}” 如果我裁剪并将图像保存为质量为65%的JPEG图像,则图像会很糟糕,并且图像尺寸仍然很大。 但是,如果我使用Image Bucket Pro并执行完全相同的操作,则JPEG看起来会更好,文件更小。 Paperclip(ImageMagick / Rmagick)如何在不降低质量的情况下提高图像质量和缩小文件大小? 另外:我尝试在图像上放置轻微的高斯模糊并剥离其EXIF数据。 但是,这对文件大小的影响可以忽略不计。

无法使用ruby on rails和paperclip gem上传zip文件

我正在开发一个rails web应用程序。 刚刚创建并准备了一些模型和东西。 应用程序非常简单。 但是现在我有一个问题,就是设置gem paperclip来为模型添加附件。 几乎一切都很好,如附加图像/ jpg甚至pdf。 但是我无法上传zip文件。 我尝试了不同的zip文件,但我总是得到:“Attachment Paperclip :: Errors :: NotIdentifiedByImageMagickError” 这是我的模特: class Order { :medium => “300×300>”, :thumb => “100×100>” }, :default_url => “/images/:style/missing.png” validates_attachment_content_type :attachment, :content_type => [“application/pdf”, “application/zip”, “application/x-zip”, “application/x-zip-compressed”,”application/octet-stream”,”image/jpg”,”image/png”] belongs_to :client has_one :status end 我正在Mac(Yosemite)上开发,通过brew安装imagemagick并使用SQLite。 我把它添加到我的Gemfile中: gem “paperclip”, “~> 4.2” gem ‘cocaine’, ‘~> 0.5.4’ 我在最后几个小时研究谷歌,有很多人在使用回形针,但我没有发现任何人在上传zip文件时遇到问题。 也许有人可以在这里帮忙。 谢谢

rails 3,paperclip(&formtastic) – 删除图像附件

我似乎无法找到所有组件中完整的示例。 我很难删除图片附件 类 class Product has_many :product_images, :dependent => :destroy accepts_nested_attributes_for :product_images end class ProductImage belongs_to :product has_attached_file :image #(etc) end 视图 {:multipart => true} do |f| %> :boolean, :label => image_tag(product_image.object.image.url(:thumb)) %> :file, :name => “Add Image” %> 调节器 class Admin::ProductsController ‘edit’ end end end 看起来不错,但是,当我选中复选框时,字面上没有任何反应。 在请求中我看到: “product”=>{“manufacturer_id”=>”2”, “size”=>””, “cost”=>”5995.0”, “product_images_attributes”=>{“0″=>{“id”=>”2”, “_destroy”=>”1”}} 但没有任何更新,产品图像也不会保存。 我错过了关于’accepts_nested_attributes_for’如何工作的基本信息吗?

使用Paperclip和AWS S3的自定义URL

我们正在使用带有aws-sdk gem的Paperclip在我们的Rails应用程序中存储和显示图像: class User ‘, medium: ‘600×600>’, thumb: ‘200×200>’ }, default_url: ‘missing_photo.png’ end 如果我在html.erb文件中使用 ,我会得到以下HTML: <img src="https://s3.amazonaws.com//users/images/000/000/001/medium/my_image.png?1419989041″> 。 如何将https://s3.amazonaws.com/作为自定义URL(如https://example.com ? 我的域名全部设置在Cloudfront及其SSL证书中。 我查阅了Paperclip S3 Storage文档 。 有一个:url选项,但我为该选项编写的任何内容似乎都无效。

无法上传图片(paperclip)和jquery mobile

无法保存头像(图片) 收到此消息:1错误禁止此通知被保存:Avatarを入力してください。 development.log Started PUT “/notices/1” for 127.0.0.1 at 2013-04-11 18:32:59 +0900 Processing by NoticesController#update as HTML Parameters: {“utf8″=>”✓”, “authenticity_token”=>”m6JK3ufruxHDD84vniXEbe4SEzRijK5HTI1SF6MkTUM=”, “notice”=>{“message”=>”xxx”, “seat”=>”1”}, “commit”=>”Save”, “id”=>”1”} User Load (2.4ms) SELECT “users”.* FROM “users” WHERE “users”.”id” = 1 LIMIT 1 Notice Load (1.4ms) SELECT “notices”.* FROM “notices” WHERE “notices”.”id” = $1 LIMIT 1 [[“id”, “1”]] (0.3ms) BEGIN (0.2ms) […]