Forum: Ruby on Rails validating presence of file uploads

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
5a992f256f765f8ee3dbb2af9d3db4e0?d=identicon&s=25 Robbie Shepherd (robbie)
on 2006-02-06 00:35
not sure whats going on here, but I'm using some pretty standard code to
manage file uploads in to a db, but having trouble detecting if the file
upload field has been filled or not.

in my Asset Model, I have:

def asset=(asset_field) = base_part_of(asset_field.original_filename)

		self.content_type = asset_field.content_type.chomp =

	def base_part_of(file_name)
		#if !file_name

		name = File.basename(file_name)

		name.gsub(/[^\w._-]/, '')

and my form has an file input field like:

<%= file_field("asset", "asset") %>

If I put in my model validates_presence_of :asset, then the upload
doesnt create a new record, even if I specify a file, so somethings not
working...any clues or workarounds?
This topic is locked and can not be replied to.