Hi, I have followed the tutorial in the AWDWR book for uploading an
image. This involves adding the following field to the form.
<%= f.file_field :uploaded_picture %>
The model then goes to work on the data to store it in the database,
with the following:
:with => /^image/,
:message => “-- you can only upload pictures”
self.name = base_part_of(picture_field.original_filename)
self.content_type = picture_field.content_type.chomp
self.data = picture_field.read
File.basename(file_name).gsub(/[^\w._-]/, ‘’ )
Now, all of this works fine, but I would like the picture upload to be
an optional feature, but if the user fills in the form and leaves the
field blank, the following error is displayed
undefined method `original_filename’ for “”:String
I’ve tried adding "unless picture_field.empty/nil? to the
uploaded_picture action, but I can’t get anything that works for both an
image being supplied and no image being supplied.
Can anyone suggest a way to get around this? Thanks.