Tag: 回形针

Paperclip错误:’avatar_file_name’需要attr_accessor所需的模型

然后,我想使用Paperclip为每个清单提供照片。 我将相应的代码添加到列表show.html.erb,listing.rb模型,listings_controller.rb和_form.html.erb部分。 当我尝试上传列表的图像时,我收到此错误: Paperclip::Error in ListingsController#update Listing model missing required attr_accessor for ‘avatar_file_name’ listing_controller的第44行: def update respond_to do |format| if @listing.update(listing_params) format.html { redirect_to @listing, notice: ‘Listing was successfully updated.’ } format.json { head :no_content } else 要尝试的一些事情:即向listing.rb模型添加一些代码,以使:avatar的可接受图像更加健壮。 以下是几个stackoverflowpost中提到的添加到listing.rb模型的内容: validates_attachment_content_type :avatar, :content_type => %w(image/jpeg image/jpg image/png) 不幸的是,当我附加图像时,我仍然会收到相同的错误。 当我没有附加图像时,我的默认图像被正确加载并正确创建列表。 我的清单模型: class Listing { :medium => “150x”, […]

从本地回形针存储迁移到S3

我们最近搬到了一个新的虚拟主机,提供有限的存储空间,因此我们试图将通过Paperclip gem上传的所有用户上传(头像,文件等)移动到Amazon S3。 我有几百个文件都对应不同的模型,我现在正试图整体迁移。 我发现这个文件引入了一个漂亮的回形针rake任务: rake paperclip:refresh:missing_styles 这个命令为我做了一些工作,但是,我注意到它只是设置文件结构而不发送任何数据 – 此外它没有设置使用has_attached_file调用中的:styles hash定义的任何缩略图。 也就是说,我在我的一个模型上设置了以下回形针: class User { :thumb => “100×100#”, :small => “150×150>”, :medium => “200×200” } end 运行命令后,这是一些示例输出: $ rake paperclip:refresh:missing_styles Regenerating User -> avatar -> [thumb, :small, :medium] Regenerating Mercury::Image -> image -> [:medium, :thumb] Regenerating Profile -> image -> [:home_feature, :large, :medium, :thumb] Regenerating […]

validation失败:上传文件的扩展名与其内容不匹配

我正在使用paperclip gem上传文件。 我的回形针gem版是paperclip-4.1.1。 在上传文件时抛出 Validation failed: Upload file has an extension that does not match its contents. 我正在尝试上传xlsx文件。 而且我已经在模型中提到了content_type。 validates_attachment_content_type :upload_file, :content_type => %w(application/msword application/vnd.ms-office application/vnd.ms-excel application/vnd.openxmlformats-officedocument.spreadsheetml.sheet), :message => ‘, Only XML,EXCEL files are allowed. ‘ 我不知道为什么会发生这种错误。 如果您对此错误有任何疑问,请分享。 摘自日志以显示validation失败: Command :: file -b –mime-type ‘/tmp/5249540099071db4e41e119388e9dd6220140513-24023-1jlg4zy’ [paperclip] Content Type Spoof: Filename file_for_bulk_upload1.xlsx ([“application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”]), content type discovered […]

base64照片和回形针-Rails

我想用回形针处理base64照片。 当我尝试: photo = Photo.new string = base64string photo.photo = StringIO.new(Base64.decode64(string)) photo.save 这是行不通的。 为什么? 提前致谢。

使用回形针上传多个文件

我在使用回形针上传多个文件时遇到问题, 我的模特就是这样 slider has_many imgarrays imgarrays has_many imageobjects imageobjects have_attachment(as for paperclip) 我在接收单个图像并使用paperclip在我的其他模型上保存它没有问题,但我不知道如何在多文件上传期间处理imgarrays param返回的数组。 这是我的rails服务器日志: Started POST “/slider” for 127.0.0.1 at 2012-07-23 10:14:17 +0800 Processing by SliderController#create as HTML Parameters: {“utf8″=>”✓”, “authenticity_token”=>”7HcHtSlOsU/bnxb9emhAsSl/GFBraIE6NxwijHl3REM=”, “slider”=>{“question”=>””, “answer”=>””, “score”=>””, “industry_name”=>””, “imgarrays”=>[#<ActionDispatch::Http::UploadedFile:0x007fb471e99f30 @original_filename="Icon.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"slider[imgarrays][]\"; filename=\"Icon.png\"\r\nContent-Type: image/png\r\n", @tempfile=#>, #<ActionDispatch::Http::UploadedFile:0x007fb471e99dc8 @original_filename="Icon@2x.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"slider[imgarrays][]\"; filename=\"Icon@2x.png\"\r\nContent-Type: image/png\r\n", @tempfile=#>, #<ActionDispatch::Http::UploadedFile:0x007fb471e99d50 […]

Paperclip在保存后重命名文件

如何在上传和保存文件后重命名文件? 我的问题是我需要自动解析有关文件的信息,以便提出文件应该像我的应用程序一样保存文件名,但我无法访问生成文件名所需的信息,直到记录为止。模型已保存。