我正在尝试上传到我构建的投资组合应用程序,特别是试图找到将 delay_job 挂接到流程中的位置。否则一切正常。现在它返回undefined method 'call' for #<Class:0xae68750>了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
Run Code Online (Sandbox Code Playgroud)
/app/models/asset.rb
class Asset < ActiveRecord::Base
attr_accessible :image, :image_file_name, :image_content_type, :image_file_size, :portfolio_item_id, :order
belongs_to :portfolio_item
has_attached_file :image,
:styles => {
:thumb => "20x20#",
:small => "100x100",
:large => "600x600>"
},
:storage => …Run Code Online (Sandbox Code Playgroud) 在使用带有导轨的回形针之前,我编写了自己的上传脚本,上传了一批图像并分配给各自的对象.但现在我需要将所有图像切换为回形针友好.
有没有办法在不使用表格的情况下将图像传递给回形针?
Image.all.each do |image|
image[:file] = image.filename
image.save
end
Run Code Online (Sandbox Code Playgroud)
我可以迭代图像对象列表并将图像文件重新分配为回形针附件的行.谢谢.
这曾经工作正常.现在我收到此错误:
rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)
** Invoke paperclip:refresh (first_time)
** Invoke paperclip:refresh:metadata (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute paperclip:refresh:metadata
rake aborted!
Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id
/Users/macuser/Sites/hq_channel/app/models/media.rb:23:in `touch_organization'
/Users/macuser/Sites/hq_channel/vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in `send'
/Users/macuser/Sites/hq_channel/vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in `evaluate_method'
/Users/macuser/Sites/hq_channel/vendor/rails/activesupport/lib/active_support/callbacks.rb:166:in `call'
/Users/macuser/Sites/hq_channel/vendor/rails/activesupport/lib/active_support/callbacks.rb:93:in `run'
/Users/macuser/Sites/hq_channel/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `each'
/Users/macuser/Sites/hq_channel/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `send'
/Users/macuser/Sites/hq_channel/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `run'
/Users/macuser/Sites/hq_channel/vendor/rails/activesupport/lib/active_support/callbacks.rb:276:in `run_callbacks'
/Users/macuser/Sites/hq_channel/vendor/rails/activerecord/lib/active_record/callbacks.rb:344:in `callback'
/Users/macuser/Sites/hq_channel/vendor/rails/activerecord/lib/active_record/callbacks.rb:251:in `create_or_update'
/Users/macuser/Sites/hq_channel/vendor/rails/activerecord/lib/active_record/base.rb:2551:in `save_without_validation!'
/Users/macuser/Sites/hq_channel/vendor/rails/activerecord/lib/active_record/validations.rb:1019:in `save_without_dirty!'
/Users/macuser/Sites/hq_channel/vendor/rails/activerecord/lib/active_record/dirty.rb:87:in `save_without_transactions!'
/Users/macuser/Sites/hq_channel/vendor/rails/activerecord/lib/active_record/transactions.rb:200:in `save!' …Run Code Online (Sandbox Code Playgroud) 我按照本指南使用回形针http://railscasts.com/episodes/134-paperclip?language=en&view=asciicast 一切都好,但请注意,要启用调整大小,您需要在服务器上安装ImageMagick.
那么我应该如何安装ImageMagick?我有WINDOWS 8并在网站http://www.imagemagick.org/下载不起作用!!!!
我正在使用Paperclip我的Rails应用程序进行附加images.我content_type在我的模型中声明了验证
validates_attachment :image,
:content_type => { :content_type => ["image/jpg", "image/gif", "image/png"] }
Run Code Online (Sandbox Code Playgroud)
我有两个例子,一个带有效图像,另一个带有无效图像.
对于无效图像,我只是将.txt文件重命名为a.png
it "Image is valid" do
image = File.new("#{Rails.root}/spec/support/right.png")
expect(FactoryGirl.build(:pin, image: image)).to be_valid
end
it "Image is invalid" do
image = File.new("#{Rails.root}/spec/support/wrong.png")
expect(FactoryGirl.build(:pin, image: image)).to have(1).errors_on(:image_content_type)
end
Run Code Online (Sandbox Code Playgroud)
我希望我的两个例子都能成功运行.但是,我的第二个例子失败了.我没有得到content_type的任何错误wrong.png.
我认为Paperclip的content_type验证实际上会检查上传文件的文件格式(二进制数据编码).但似乎在这里,它只是检查文件扩展名.此验证仅检查上传文件的扩展名吗?
我可能在这里遗漏了一些东西(配置?).Paperclip中是否还有其他验证可用于实现此目的?或者在这种情况下我应该选择自定义验证器吗?
我正在使用 Paperclip gem 并保存我的每个图像的三个副本。我的路径看起来像这样:
“img/thumb/f80386a363e077dc08fb80a5c8908c1d78b7.png”
如何从 Paperclip 附加文件对象中仅提取此路径的哈希部分?
显然我可以从中解析出哈希值,但是加载时间对我的应用程序来说非常重要,我更愿意快速提取每个图像的哈希值。所有文件都存储为 jpg,因此这也可以附加在客户端上。我在 Paperclip 对象周围戳了一下,但找不到访问哈希的方法。
这真让我抓狂...
我在这里看到了几个问题与nokogiri(一个在这里),但它们与脚本有关.我有一个完整的rails应用程序,我刚刚安装了paperclip和amazon-aws,当我进行捆绑安装时也下载了nokogiri ..
gem dependency paperclip
...
nokogiri (>= 0, development)
...
Run Code Online (Sandbox Code Playgroud)
这就是这个宝石被引入的地方..
我读到Nokogiri应该在我的gemfile中,所以我做了一个
gemfile.rb =>
gem 'nokogiri'
gem 'aws-sdk'
gem 'paperclip'
Run Code Online (Sandbox Code Playgroud)
现在我的本地服务器无法启动...
nokogiri-1.6.2.1/lib/nokogiri.rb:29:in `require': cannot load such file -- nokogiri/nokogiri (LoadError)
Run Code Online (Sandbox Code Playgroud)
我也尝试过nokogiri 1.4.4 ......
以前(在我的gemfile中没有nokogiri)服务器会加载,但是当我尝试上传图像时会出现加载错误...同上面的错误
cannot load such file -- nokogiri/nokogiri
Run Code Online (Sandbox Code Playgroud)
关于nokogiri的thotbot/paperclip文档中没有任何内容.我试过了
gem install nokogiri
Run Code Online (Sandbox Code Playgroud)
和
gem pristine nokogiri
Run Code Online (Sandbox Code Playgroud)
没有骰子..
我在捆绑上注意到这条消息:
IMPORTANT! Nokogiri builds and uses a packaged version of libxml2.
If this is a concern for you and you want to use the system library
instead, …Run Code Online (Sandbox Code Playgroud) Paperclip::AdapterRegistry::NoHandlerError at /admin/posts/1 No handler found for foo.png
Run Code Online (Sandbox Code Playgroud)
我有一个带有Active Admin的rails 4应用程序,我试图将图像上传到我的Post模型,但我收到了上述错误.这是我的设置
ruby '2.1.2'
gem 'rails', '4.1.6'
gem 'activeadmin', github: 'gregbell/active_admin'
gem 'paperclip'
gem 'aws-sdk'
Run Code Online (Sandbox Code Playgroud)
class Post < ActiveRecord::Base
has_attached_file :image, styles: {
thumb: '100x100>',
square: '200x200#',
medium: '300x300>'
}
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
end
Run Code Online (Sandbox Code Playgroud)
permit_params :image
form do |f|
f.inputs do
f.input :image, as: :file, hint: (f.template.image_tag(f.object.image.url(:thumb)) if f.object.image?)
end
f.actions
end
Run Code Online (Sandbox Code Playgroud)
Paperclip::Attachment.default_options[:storage] = :s3
Paperclip::Attachment.default_options[:s3_host_name] = 's3-eu-west-1.amazonaws.com'
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename' …Run Code Online (Sandbox Code Playgroud) 我在我的一个应用程序中设置paperclip gem时遇到问题.
我No handler found for尝试保存上传的文件时收到错误消息.
我做过的事情
移民:
add_attachment :orders, :file
Run Code Online (Sandbox Code Playgroud)模型:
has_attached_file :file
validates_attachment_content_type :file, :content_type => /\Aimage\/.*\Z/
Run Code Online (Sandbox Code Playgroud)控制器:
def order_params
params.require(:order).permit(:file)
Run Code Online (Sandbox Code Playgroud)视图:
form_tag url, method: :post, html: {multipart: true}
...
= file_field_tag 'order[file]', disabled: true, id: 'mtd_file',accept: 'image/png,image/gif,image/jpeg'
Run Code Online (Sandbox Code Playgroud)当我尝试在我的控制器中执行时,我Order.create params[order]得到错误
找不到"file.jpg"的处理程序
当我查看order[file]param时,我发现它是一个字符串file.jpg(上传文件的名称).
ruby ruby-on-rails image-uploading paperclip ruby-on-rails-4
我正在使用paperclip gem将文件上传到数据库.当我选择要上传的文件并去创建它时,下一页应该重定向到根路径.相反,我在浏览器中收到"Method Not Allowed".我打开开发工具,控制台说:无法加载资源:服务器响应状态为405(方法不允许)我的日志如下所示:
Started POST "/assets" for ::1 at 2015-08-20 10:41:11 -0400
Run Code Online (Sandbox Code Playgroud)
并一直挂钩,直到我回到另一页.
这是我的控制器
class AssetsController < ApplicationController
# before_filter :authenticate_user!
def index
@assets = current_user.assets
end
def show
@asset = current_user.assets.find(params[:id])
end
def new
@asset = current_user.assets.build
end
def create
@asset = current_user.assets.build(asset_params)
if @asset.save
flash[:success] = "The file was uploaded!"
redirect_to root_path
else
render 'new'
end
end
def edit
@asset = current_user.assets.find(params[:id])
end
def update
@asset = current_user.assets.find(params[:id])
end
def destroy
@asset = current_user.assets.find(params[:id])
end
private
def …Run Code Online (Sandbox Code Playgroud) paperclip ×10
ruby ×3
activeadmin ×1
amazon-s3 ×1
delayed-job ×1
forms ×1
imagemagick ×1
rspec ×1
upload ×1
windows ×1