Reputation: 7003
I installed it by following the manual on paperclip github page and I get the given error. What am I doing wrong?
I have 4 input fields: title (text_field
), description (text_area
), price (text_field
) and image (file_field
). Why am I even getting this error with the prefix title
in it? What has the title
field got to do with it, are there any conflicts maybe? I did create and run the migrations so this is realy kind of weird I think.
Any help appreciated. Thanks.
EDIT:
The migration is as follows:
class AddImageColumnsToProducts < ActiveRecord::Migration
def change
add_attachment :products, :image
end
end
It results like so:
image_file_name varchar(255)
image_content_type varchar(255)
image_file_size int(11)
image_updated_at datetime
Model:
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
Controller:
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
Upvotes: 0
Views: 160
Reputation: 5214
The issue is with your validation. The line which says
validates :title, :content, :image, :attachment_presence => true
assumes title, content & image as 3 image-based attributes. But, I understand that only 'image' is the image-based field. So, your code should rather be:
validates :title, :content, :presence=>true
validates :image, :attachment_presence => true
Also, I don't see the 'content' field in the request-log. I guess, you mean 'description'. Make sure you have the same attribute-names in the model-validations, database-schema & view files.
Upvotes: 1