Tag: 回形针

没有出现与回形针的路轨图象

我想在我的主页上显示一个头像。 我正在使用Paperclip来做到这一点。 但是,每当我尝试显示图像时,我都会得到: 这就是我的代码: 视图: Users @ user.username确实正确显示。 和我试图展示的任何其他财产一样。 debug语句返回:“— /images/original/missing.png?1400548644” 但是,我可以在这里找到图像: ./public/system/users/avatars/000/000/001/original/myImage.png 但是在这里找不到: ./app/assets/images 是否可能在错误的地方得救? 以下是我的其余代码供参考: 模型: class User { :medium => “300×300>”, :thumb => “100×100>” }, :default_url => “/images/:style/missing.png” validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/ validates :username, :presence => true, :uniqueness => true, :length => { :in => 3..20 } validates :email, :presence => […]

使用Paperclip将图像发布请求通过http上传到其他应用程序

我可以使用paperclip将图像附件上传到我的应用程序。 但我想通过法拉第连接将图像发送到另一个应用程序。 其他属性已成功发送但未附加图像。 我不确定应该怎样做才能实现这一目标。

Ruby on Rails – 将方法的返回值传递给has_attached_file。 我的Ruby语法错了吗?

我正在编写我的第一个RoR应用程序,目前我正致力于允许用户上传图像。 我正在使用Paperclip来达到这个目的。 其中一个步骤涉及将has_attached_file添加到我的模型中: class MyModel “, small: “60×75#>” } #… end 如果我这样做,一切顺利(或者似乎)。 但是我还需要在其他地方访问与整数相同的常量值,所以我添加了一个哈希: class MyModel “, small: “60×75#>” } def picture_sizes { large: {width: 120, height: 150}, small: {width: 60, height: 75} } end #… end 这会产生丑陋的冗余。 所以我考虑编写一个从第二个哈希生成第一个哈希的方法,就像这样 class MyModel ” end return result end #… end 但这会引发一个错误: undefined local variable or method `picture_sizes_as_strings’ for […]

Windows上的Paperclip – 未定义的方法`split’代表nil:NilClass

当我试图保存上传的文件时,我正在为nil获取未定义的方法`split’:NilClass @user.avatar=params[:user][:avatar] 这是服务器日志中的错误: [32mCommand[0m :: identify -format %wx%h “C:/progs/web/ror_site_1/tmp/Rus220120701-4976-1sky1nn.jpg[0]” [32mCommand[0m :: identify -format %m “C:/progs/web/ror_site_1/tmp/Rus220120701-4976-1sky1nn.jpg[0]” [32mCommand[0m :: identify -format %m “C:/progs/web/ror_site_1/tmp/Rus220120701-4976-1sky1nn.jpg[0]” [32mCommand[0m :: convert “C:/progs/web/ror_site_1/tmp/Rus220120701-4976-1sky1nn.jpg[0]” -resize “300×300>” “C:/progs/web/ror_site_1/tmp/Rus220120701-4976-1sky1nn20120701-4976-a9j1sh” [32mCommand[0m :: file -b –mime “C:/progs/web/ror_site_1/tmp/Rus220120701-4976-1sky1nn20120701-4976-a9j1sh20120701-4976-tm6qoj” [1m[36m (0.0ms)[0m [1mROLLBACK[0m Completed 500 Internal Server Error in 406ms NoMethodError (undefined method `split’ for nil:NilClass): app/controllers/users_controller.rb:94:in `block in update’ app/controllers/users_controller.rb:93:in […]

Ruby on Rails – 如何从嵌套模型委派错误消息

class User include Mongoid::Document has_many :images accepts_nested_attributes_for :image end class Image include Mongoid::Document include Mongoid::Timestamps include Mongoid::Paperclip has_mongoid_attached_file :uploaded_image, :path => “:rails_root/public/uploads/:class/:id/:basename.:extension”, :url => “public/uploads/” validates_attachment_content_type :uploaded_file, :content_type => “application/png”, :message => “error massage” belongs_to :user delegate :url, :path, to: :uploaded_image, allow_nil: true, prefix: false end 如果:uploaded_image无效,如何将Image中的错误委托给用户? 例如: user_image = user.images.build(uploaded_image: new_image.path) user_image.save 如果uploaded_image无效,应该引发错误。

回形针上传并显示图像不起作用

我在Windows 7上安装了paperclip – > 5.1和最新的ImageMagick(是的……我知道)运行Ruby 2.3.3和Rails 5.1.4。 我按照回形针说明的建议安装了file.exe,并将“C:\ Program Files(x86)\ GnuWin32 \ bin”添加到了我的PATH中。 当我上传我的照片时,我收到以下错误: ActionController::RoutingError (No route matches [GET] “/images/medium/missing.png”): 当我尝试查看显示页面以查看图像时,我收到以下错误: ActionController::RoutingError (No route matches [GET] “/system/recipes/images/000/000/005/medium/Capture777.PNG”): 您能否就如何正确上传我的图片并进行展示给我指导? 我假设错误会给出一些输入。 我试图关注其他SO文章但到目前为止没有任何帮助。 这是我的routes.rb Rails.application.routes.draw do resources :recipes root “recipes#index” end 这是我的控制器show / new actions和find_recipe params def show @recipe = find_recipe end def new @recipe = Recipe.new end […]

Paperclip与Imagemagick结合使用可以保存图像,但不会在网站上显示图像

我正在使用paperclip和Imagemagick将图像添加到网站。 我在网站上有一个表单供用户上传图片。 当我上传图片时,它不会出现任何错误。 当我检查rails控制台时,图像将以正确的大小和所有内容保存。 当我检查项目文件夹时,图像也会保存在那里。 但是当我尝试显示时,我在网站上得到以下屏幕(只添加了一个图像,只有左边的图像应该显示,其余的标记是因为没有添加图像): 屏幕截图 这是我的index.html页面: There are no books currently in this category <a href="https://stackoverflow.com/books/”> 我在终端窗口中收到以下错误消息:终端窗口的屏幕截图 请让我知道为什么会这样。 谢谢。

回形针是否需要所有4列(_file_name,_content_type等)?

我想知道Paperclip是否确实需要数据库中的所有四列: add_column :users, :avatar_file_name, :string add_column :users, :avatar_content_type, :string add_column :users, :avatar_file_size, :integer add_column :users, :avatar_updated_at, :datetime 我可以添加avatar_file_name吗? 而不是添加其他3列? 这是因为我不会使用paperclip而不是filecolumn gem。 它仅使用1列我不想填写回形针支持的所有列。

回形针图像未显示在rails app中

我正在使用回形针将图像上传到网站,但是当我这样做时,它会显示带有问号的图像占位符,而不是图像本身。 我究竟做错了什么? 在模型中: attr_accessor :photo_file_name attr_accessor :photo_content_type attr_accessor :photo_file_size attr_accessor :photo_updated_at attr_accessible :photo #paperclip——————————- has_attached_file :photo, :url => “/:attachment/:id/:style/:basename.:extension”, :path => “:rails_root/public/:attachment/:id/:style/:basename.:extension” 在视图中: Title: 并以我的forms:

paperclip找不到“file.jpg”rails 4的处理程序

我在其中一个应用程序中设置paperclip gem时遇到问题。 当我尝试保存上传的文件时,我No handler found for错误消息的No handler found for 。 我做过的事情 移民: add_attachment :orders, :file 模型: has_attached_file :file validates_attachment_content_type :file, :content_type => /\Aimage\/.*\Z/ 控制器: def order_params params.require(:order).permit(:file) 视图: 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’ 当我尝试在我的控制器中执行Order.create params[order]我收到错误 找不到“file.jpg”的处理程序 当我查看order[file] param时,我发现它是一个字符串file.jpg (上传文件的名称)。