Oh, thanks for the advise on the way I have the fk setup! I'm guessing that will really help in getting things straightened out.
Jet On Sep 16, 2:28 pm, Matt Jones <[email protected]> wrote: > On Sep 16, 2009, at 5:05 PM, blueHandTalking wrote: > > > > > > > > > I am still working on my attempt to have Paperclip do an 'Ajaxy' > > upload > > from 3 different forms that save to a single record which has fields > > for 3 images. > > The page I am doing this from is generated from a ProjectsController, > > which creates > > a @project instance and a @photo instance. the project has_one photo, > > and the > > photo belongs_to the project. > > > I redirect from a 'new' method where the project and photo are saved > > to an 'edit' method. > > In edit, I am doing the following: > > > @project = Project.find(params[:id]) > > @photo = @project.photo > > > The reason for this is to have the same photo record available to all > > 3 forms, and the > > project_id also available. > > > In my forms I have a method 'upload_main' (and similar for the 2 > > other forms). > > This is handled in PhotosController by: > > > @photo = Photo.find_by_project_id(params[:id]) > > > if @photo.update_attributes(params[:photo]) > > responds_to_parent do > > render :action => 'main_Photo.rjs' > > end > > [snip] > > <input type="hidden" name="#{param_name_for_this}[project_id]" > > value="&[email protected]"/> > > <input type="hidden" name="#{param_name_for_this}[id]" > > value="&[email protected]_id"/> > > > ...and the following is in my Apache Application log: > > > Processing PhotosController#upload_main (for 66.165.26.17 at > > 2009-09-16 20:32:07) [POST] > > Parameters: {"photo"=>{"project_id"=>"298", "mainimg"=>#<File:/tmp/ > > RackMultipart.25933.1>, "id"=>"492"}, "page_path"=>"projects/edit", > > "authenticity_token"=>"iiwoOHgAaBTCv/U4xhmvlR2qleLbG+Ov70cubJ7G8jQ=", > > "after_submit"=>"stay-here"} > > > So the correct photo id is in the hash, along with the project_id. > > > Where am I missing the boat on not actually getting the @photo saved > > in PhotosController? > > I'm not sure why this isn't just throwing an error - you're looking up > a Photo with params[:id], but not passing anything in that position in > params. You've got a project_id and id in params[:photo], but they'd > be accessed as params[:photo][:project_id], for example. > > There's also something weird with your models - do you really have a > project_id field on Photo *and* a photo_id field on Project? That's a > quick ticket to some confusion - you only need the FK on one side (the > belongs_to) with a corresponding has_(one|many) on the other end. > > --Matt Jones --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Hobo Users" 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/hobousers?hl=en -~----------~----~----~----~------~----~------~--~---
