Hi,
I’m using file_column to do the image uploads .i want to know how to do
the validation to upload only jpg or png or gif images.
RIght now the user can upload any type of file.I want to restrict it
only image type.
i also want to know how to flash the error message in my view.
class Album < ActiveRecord::Base
file_column :image
validates_file_format_of :image, :in => [“gif”, “jpg”], :message => “Hey, Upload only GIF and JPG format”
validates_filesize_of :image, :in => 1.kilobytes…5000.kilobytes
end
in view
Hi,
I have a problem the validations are not happening in my model .
i even tried validating somethgin else like
validates_presence_of :comments where comments is a text field
even this validation fails.
The validation in AR should work properly, as long as the column name in
your table is correct, no matter of the type data is for
validate_presence_of. if it is not working, you will have error message.
If you want validate a field that is not from your table, you should
add attr_reader :anyname or attr_accessor :anyname or in your AR you can
validate using :
Hi ,
It was syntax error while typing in the forum.it is as u have mentioned
only.
THe thing is .
i’m doing a image upload to iframe using ajax.
is that where the problem lies??
so when i hit the upload button it actually does not show the create
action in
the firebug .
Hi,
I have a problem the validations are not happening in my model .
i even tried validating somethgin else like
validates_presence_of :comments where comments is a text field
even this validation fails.
Can u please help???
The validation in AR should work properly, as long as the column name in
your table is correct, no matter of the type data is for
validate_presence_of. if it is not working, you will have error message.
If you want validate a field that is not from your table, you should
add attr_reader :anyname or attr_accessor :anyname or in your AR you can
validate using :
#it is the same like attr_accessor
def anyname=(new_name)
if new_name.nil?
errors.add(“anyname”, “is empty.”)
end
end
. yeah such as a josh said, Paste us more details.