Please help.
--
Posted via http://www.ruby-forum.com/.
>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.
class Album < ActiveRecord::Base
file_column :image
validates_file_format_of :image, :in => ["gif", "jpg"]
validates_filesize_of :image, :in => 1.kilobytes..5000.kilobytes
end
Good Luck,
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
Reinhart Ariando
YM : booking2heaven
Web: http://teapoci.blogspot.com
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
------------
in view
------------
<%= error_messages_for "image" %>
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.
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
Reinhart Ariando
YM : booking2heaven
Web: http://teapoci.blogspot.com
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
Hi,
class Entry < ActiveRecord::Base
has_many :problems
belongs_to :reply
require 'remote_uploads.rb'
file_column :image, :magick => {
:versions => { "thumb" =>"50x50"}
}
validates_file_format_of :image, :in => ["gif", "jpg","png"], :message
=>"must be a jpg,png or gif file type"
validates_presence_of :comments
end
table structure:
comments is a column in the entry table.
in my view i have
<%= error_messages for 'entry' %>
i hope the above info is sufficient.
the correct is <%= error_messages_for 'entry' %>
tell me if it works.
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 .