Skip to content
Squeegy edited this page Sep 12, 2010 · 2 revisions

Usage

These assignment methods can be used in two ways. First they can be called directly.


my_photo.image_file = File.new('path/to/file.png', 'rb')

Or they can be called via mass assignment.


Photo.new(:image_file => File.new('path/to/file.png', 'rb')
Photo.new(params[:photo]) #where params[:image_file] is an uploaded image

Assignment methods

image_file = file

This is the most common assignment method. This will work with an instance of any IO object, such as File or StringIO. it will also work with file upload fields in your forms.

image_file_url = url

Fetches an image from a url on the internet and saves it with the record.

image_file_string = file_data

Reads the image from a string of file data. This can be used with the result of something like File.read('my_image.jpg', 'rb').

image_file_base64 = base64_data

Reads the image from a string of base64 encoded file data.

image_file_temp = temp_file_name

This one is used internally to make forms redisplay safe. It expects the named of a file in your apps tmp directory. You probably shouldn’t need to use this one.

Clone this wiki locally