【发布时间】:2013-12-17 23:55:14
【问题描述】:
我按照回形针 github 页面上的手册安装了它,但我得到了给定的错误。我做错了什么?
我有 4 个输入字段:标题 (text_field)、描述 (text_area)、价格 (text_field) 和图片 (file_field)。为什么我什至会收到带有前缀 title 的错误? title 字段与它有什么关系,可能有任何冲突吗?我确实创建并运行了迁移,所以我觉得这真的很奇怪。
任何帮助表示赞赏。谢谢。
编辑:
迁移如下:
class AddImageColumnsToProducts < ActiveRecord::Migration
def change
add_attachment :products, :image
end
end
结果如下:
image_file_name varchar(255)
image_content_type varchar(255)
image_file_size int(11)
image_updated_at datetime
型号:
class Product < ActiveRecord::Base
has_attached_file :image, :styles => { :medium => "600x600>", :thumb => "258x258>" },
:default_url => "images/:style/:slug.png"
validates :title, :content, :image, :attachment_presence => true
validates_with AttachmentPresenceValidator, :attributes => :image
end
控制器:
def create
@product = Product.new(product_params)
@product.image = params[:product][:image]
respond_to do |format|
if @product.save
format.html { redirect_to @product, notice: 'Product was successfully created.' }
format.json { render action: 'show', status: :created, location: @product }
else
format.html { render action: 'new' }
format.json { render json: @product.errors, status: :unprocessable_entity }
end
end
end
【问题讨论】:
-
您能否显示包含图像的表格的参数和表格列?
-
能否请您也粘贴确切的错误。
-
感谢您的错误。您也可以发布型号代码吗?我想知道你是否在你的模型中正确使用了 PaperClip
-
另外,发布您的控制器代码。你做了一个简单的@product = Product.new(params[:product]) 还是一些花哨的东西?如果您更新了问题,请在此处发表评论。这是您修改后我收到通知的唯一方式。
-
@SatyaKalluri 更新了它:)
标签: ruby-on-rails file-upload ruby-on-rails-4 paperclip