Also your message mentioned you need the id of the project before you save the project. The project won't get an id until it is saved.
Brett On Sep 13, 9:46 am, Brett Nelson <[email protected]> wrote: > Have you tried it like this? > > new_photo = @project.build_photo # this should set the project_id in > the new photo record > new_photo.user = current_user # you shouldn't have to call out the id > field names explicitly > new_photo.save > > Or like this > > new_photo = @project.photos.new # this should set the project_id in > the new photo record > new_photo.user = current_user > new_photo.save > > Brett > > On Sep 12, 10:12 am, blueHandTalking <[email protected]> wrote: > > > I have the following relationships: > > > Photo > > belongs_to :user > > belongs_to :project, :creator => true > > > ProjectDetail > > belongs_to :user > > belongs_to :project, :creator => true > > > Project > > belongs_to :user, :creator => true > > has_one :photo > > has_one :project_detail > > > With a 'new' method, I create a project in ProjectController. > > I set up and save all relationships manually. This I do because > > I need the id of project because I will be saving photo before I save > > the project. An abbreviated representation of this is: > > > @project = Project.new > > @project.user_id = current_user.id > > @project.save > > > @project.build_project_detail > > @project.project_detail.user_id = current_user.id > > @project.project_detail.project_id = @project.id > > @project.project_detail.save > > > @project.build_photo > > @project.photo.user_id = current_user.id > > @project.photo.project_id = @project.id > > @project.photo.save > > > The very strange behavior that is occuring is that everything is > > saved > > correctly, > > > EXCEPT > > > @project.photo.project_id = @project.id > > > What is perplexing about this is that the project_detail saves the > > @project.id, > > and basically the photo and project_detail model are pretty much the > > same. > > > The photo model uses :has_attached_file with Paperclip, if that is at > > all relevant. > > > Would appreciate any thoughts, or suggestions as to how I may be able > > to track this > > down. > > > Cheers, > > > Jet --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
