On Aug 11, 10:10 pm, Rob Wilkerson <[email protected]> wrote:
> 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?
>
why not do the assignment from the before_create callback ? I'm not
entirely sure why you're trying to do this .
Fred
> In my ImagesController, I currently have:
>
> def create
> @image = Image.new( params[:image] )
> # @binary = Binary.new
>
> # if @binary.upload( params[:image][:upload] )
> # �[email protected]_id = @binary.id
>
> if @image.save
> flash[:notice] = "Successfully created image."
> redirect_to @image
> else
> render :action => 'new'
> end
> end
> end
>
> 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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---