Tag: 回形针

Paperclip has_attached_file无法使用Rails的establish_connection

我正在尝试使用establish_connection从回形针访问图像。 这是我的模型article.rb的代码 class Article < ActiveRecord::Base if Rails.env.production? establish_connection SECONDARY_DB_CONFIG else establish_connection "article_#{Rails.env}" end has_many :assets, dependent: :destroy accepts_nested_attributes_for :assets validates_associated :assets end file asset.rb class Asset { :large=> “1200×700”,:medium => “800x” } validates_attachment_content_type :image, :content_type => [“image/jpg”, “image/png”, “image/jpeg”] end 并且代码在视野中 0 %> ” alt=”” /> 它抛出这样的错误 资产的未定义方法`has_attached_file’(调用’Asset.connection’建立连接):Class

使用关联和回形针附件复制rails对象

我有一个有几个关联的对象。 这些相关对象中的一些具有存储在S3处的回形针附件。 如果我复制对象和关联它工作正常但附件不重复。 这在没有得到图像的情况下工作: copy_salon = @salon.dup copy_salon.about_us_versions = @salon.about_us_versions.collect{|about_us| about_us.dup} 我试图得到这样的图像链接: copy_salon = @salon.dup copy_salon.about_us_versions = @salon.about_us_versions.collect{|about_us| about_us_dup = about_us.dup if about_us.about_us_image then about_us_dup.about_us_image = about_us.about_us_image end if about_us.team_image then about_us_dup.team_image = about_us.team_image end about_us_dup } 但后来我收到错误’无法将nil转换为String’,可能是因为并非所有图像都已设置。

使用Paperclip上传到Heroku上的S3(delayed_job问题)

我正在尝试上传到我构建的投资组合应用程序,特别是试图找到将delayed_job挂钩到进程的位置。 这一切都是有效的。 现在它在app/controllers/portfolio_items_controller.rb:18:in ‘create’上返回undefined method ‘call’ for # app/controllers/portfolio_items_controller.rb:18:in ‘create’所以这是我的模型和控制器的那部分……任何人都可以看到任何可能的东西出错了? 我现在使用的钩子是我从这个博客得到的: http : //madeofcode.com/posts/42-paperclip-s3-delayed-job-in-rails /app/controllers/portfolio_items_controller.rb def create @portfolio_item = PortfolioItem.new(params[:portfolio_item]) if @portfolio_item.save flash[:notice] = “Portfolio item created. As soon as files are uploaded Portfolio item will be made live.” redirect_to @portfolio_item else render :action => ‘new’ end end /app/models/asset.rb class Asset { :thumb => “20×20#”, […]

Rails Paperclip和AJAX表单

我有一个包含表单的模式,用户可以在其中上传照片。 正确上传照片后,我想通过Ajax响应并显示消息。 不幸的是,表单是以HTML格式提交的,而不是JS格式的。 任何的想法? 表格代码: {:controller => ‘objects’, :action => ‘create’}, :remote=> true, :html => { :multipart => true }) do |f| %> Upload 谢谢

当文件不是有效的附件内容类型时,Paperclip :: NotIdentifiedByImageMagickError

当我尝试上传不在[“image/jpg”, “image/jpeg”, “image/gif”, “image/png”, “image/pjpeg”, “image/x-png”]的文件时,我系统地出错了[“image/jpg”, “image/jpeg”, “image/gif”, “image/png”, “image/pjpeg”, “image/x-png”] 当我尝试上传像’wav’这样的文件时,我收到了这条消息 * Photo /var/folders/nT/nTr21TWfFRO7r3cyG-h-7++++TM/-Tmp-/Clip audio 01,39154,0.wav is not recognized by the ‘identify’ command. * Photo /var/folders/nT/nTr21TWfFRO7r3cyG-h-7++++TM/-Tmp-/Clip audio 01,39154,0.wav is not recognized by the ‘identify’ command. * Photo content type Accepted files include: jpg, gif, png 因此,它检测到该文件不是图像并显示我的消息”Accepted files include: jpg, gif, png”但是在我的照片未被’identify’命令识别之前我已经包含了这个额外的消息…上传工作正常对于图片 我的代码是: 控制器: def […]

Paperclip安装后未定义的方法has_attached_file?

不确定我是否已经在这里做了一切。 我将Paperclip gem添加到我的Gemfile中并进行了bundle install。 我按照Paperclips Github页面上的自述文件说明进行操作。 我不确定是否需要安装ImageMagick。 但是,我在Github上发现了一个在Snow Leopard上安装的脚本,所以我跑了: rails plugin安装http://github.com/masterkain/ImageMagick-sl.git 但是,现在我得到了Undefined方法has_attached_file 我是Rails和编程的新手。 对我来说大部分都是非常先进的,但到目前为止,我已经设法解决了问题。

使用回形针在MODEL中使用Rails环境URL

在我的用户模型中,我有一个像这样的回形针设置: has_attached_file :profile_pic, :styles => {:large => “300×300>”, :medium => “150×150>”, :small => “50×50#”, :thumb => “30×30#” }, :default_style => :thumb, :default_url => ‘/images/:attachment/default_:style.png’, 如何制作默认url,包含完整url? http://0.0.0.0:3000/images/:attachment/default_:style.png or http://sitename.com/images/:attachment/default_:style.png

Rails 4,Paperclip 4.2.1在二进制文件上传时出错

我使用rails 4和paperclip 4.2.1进行了以下设置 class Post allowed_content_type, :message=> “Only #{allowed_content_type} is allowed” 我在我的application.rb中有这个 <body data-controller="” data-action=”” data-no-turbolink=”true”> 后控制器很简单 def update Post.transaction do @post.attributes = (artifact_params) if @artifact.errors.blank? redirect_to(@artifact, :notice => ‘Evidence item updated successfully’) else render :action => ‘edit’ raise ActiveRecord::Rollback end 它与所有其他文件类型完美配合。 我尝试二进制文件时出错。 这是错误: Posts中的编码:: UndefinedConversionError #refate app / views / layouts / application.html.erb第58行引出: 56: […]

如何删除回形针中的现有样式尺寸

我知道你可以为纸夹添加新的样式然后使用过程! 强制回形针填写缺失样式的方法。 但是,如果你想放弃你不再使用的旧款式,该怎么办呢? 例如,我有iphone和ipad的样式,我改变了主意,反而喜欢:大和中等,尺寸略有不同而不是:iphone和:ipad。 特别是我在s3上托管我的图像,因为我的应用程序是在heroku上。 我想删除s3上与iphone和:ipad样式有关的所有文件夹。 是否有删除选择样式的rake任务?

使用Paperclip和Amazon s3上传照片时缺少凭据

我在使用Paperclip将照片上传到S3时遇到问题。 照片正确下载到网站,但尝试上传新的照片会出现“凭据丢失”消息。 我已经尝试重置我的S3密钥,尝试更改编码中变量的访问权限,而不是更有效。 我几乎可以肯定这是照片问题,因为如果我提交没有照片的表单,它会正确提交(尽管没有照片)。 这是模型(两个模型之一,但脚本是相同的): class Outfit :destroy has_many :like_relationships, :as => :liked, :dependent => :destroy belongs_to :user validates :gender, :presence => true validates :photo_file_name, :presence => true has_attached_file :photo, :storage => :s3, :bucket => ‘cold_fusion’, :s3_credentials => { :access_key_id => ENV[‘S3_KEY’], :secret_access_key => ENV[‘S3_SECRET’] } end 这是错误报告 OutfitsController中的RuntimeError #create RuntimeError in OutfitsController#create Missing credentials […]