File upload validations?


#1

It appears there are no validation class methods that can be used on
file uploads? These would be
nice :slight_smile:

validates_file_type
validates_file_size

csn


Yahoo! FareChase: Search multiple travel sites in one click.


#2

cool_screen_name90001 wrote:

It appears there are no validation class methods that can be used on
file uploads? These would be
nice :slight_smile:

validates_file_type
validates_file_size

csn


Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com

Those validations would only make sense on a UploadedFileClass…As this
class doesnt exsist in rails, there’s no need for these validations in
the core…

But it would be an excellent code snippet…

Mikkel


#3

Turns out it’s pretty easy.

In item’s create view:

<%= file_field ‘item’, ‘file’ %>

and item’s model:

class Item < ActiveRecord::Base
validate :check_file_size

def check_file_size
	if @file and @file.size > 20000
		errors.add('file', 'too big')
	end
end

def file
	@file
end

def file=(file)
	@file=file
end

end

csn

— Mikkel B. removed_email_address@domain.invalid wrote:

But it would be an excellent code snippet…

Mikkel

–
Posted via http://www.ruby-forum.com/.


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Yahoo! FareChase: Search multiple travel sites in one click.