I have an Image model that is supported by a Binary model. The latter
contains metadata about a physical file and performs all operations
related to the physical file (I will eventually have other models for
different file types). I have a binary.upload method working, but I'd
like to move its call from my ImagesController into the
image.before_create callback. The binary.upload method returns the
binary object. Since my Image model belongs_to my Binary model, I need
the binary.id value to save the Image. How can I access that?
In my ImagesController, I currently have:
@image = Image.new( params[:image] )
# @binary = Binary.new
# if @binary.upload( params[:image][:upload] )
# @image.binary_id = @binary.id
flash[:notice] = "Successfully created image."
render :action => 'new'
I've commented the code that I'd like to move into the Image model
callback, but I'm not sure how the mechanics would work. Can someone
point me in the right direction?
Any help would be much appreciated. I'm still learning how to access
and manipulate objects in Ruby, as you can see.