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
This works great, my current page is updated by the rjs via the
<form target="main_upload">
attribute, and the <iframe name="main_upload">
What is bad is that the record is not being written to the d.b.
Since the render :action is within an if statement for updating
@photo, this is perplexing.
I have the following hidden fields in my form:
<input type="hidden" name="#{param_name_for_this}[project_id]"
value="&@project.id"/>
<input type="hidden" name="#{param_name_for_this}[id]"
value="&@project.photo_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?
When I have this working, I will create a synopsis of steps I have
taken, perhaps some beginning of
recipe for using Paperclip and responds_to_parent for Ajaxy upload and
display in current page,
if anyone thinks that would be worthwhile.
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
-~----------~----~----~----~------~----~------~--~---