multi model form for attachments
RyanL
8 posts
|
hey Ryan, got that form working and liked it so much, thought i would use the technique for image attachments and mimic gmail’s add attachment. i have it working for pages, so you can add, edit, add, remove to your hearts content (and bandwidth), and i would like to do the same for events and another model. Do I have to worry about the helper functions interfering with one another (ie new_attachment_attributes= in page.rb and event.rb or the helpers) since they will all have many attachments? Or are they all independent from each other as long as they are in there own respective model_helper.rb. I only ask b/c i tried this on events quickly and the params would keep saying page[attributes][...][...] instead of event[attributes][...][...] |
RyanL
8 posts
|
I went back and made the fields for def names unique and made sure the right partials were called. Not sure what is hapening here though. when i update an image from page, the params say “page”=>{“existing_page_attachment_attributes”=>{“446”=>{“uploaded_data”=>”“}, “401”=>{“uploaded_data”=>#<file: /> but events say existing_attachment_attributes”=>{“456”=>{“uploaded_data”=>#<file: /> how do get the params to say event => ..... |
Ryan Bates
29 posts
|
Methods in the Page model won’t interfere with methods in the Event model. It’s okay for separate classes to have the same method names. Just make sure when you submit the events form, it goes to your Events controller and creates a new event model (or updates it). Make sure it’s not going to the Pages controller. As for why events are behaving differently from pages, I’m not sure. Rails treats both the same way, so there must be some difference in the code. Take a closer look at how the form fields are rendering. It may help to start by browsing the HTML source and compare the two forms. |
RyanL
8 posts
|
hey Ryan, i went through, and copied the code from the working model’s controller, helper, view, and partial, but still the same error. New images are saved, but only edited urls. I posted up the code on the rails forum. Would you be able to take a quick look to see if i am forgetting something minor? the html renders to the same.
Image Attachment for Event<br/> doesn't save
<input id="event_existing_attachment_attributes_476_uploaded_data" name="event[existing_attachment_attributes][476][uploaded_data]" size="30" type="file" />
<a href="#" onclick="$(this).up('.attachment').remove(); return false;">remove</a>
Image Attachment for Page<br/>
<input id="page_existing_page_attachment_attributes_386_uploaded_data" name="page[existing_page_attachment_attributes][386][uploaded_data]" size="30" type="file" />
<a href="#" onclick="$(this).up('.attachment').remove(); return false;">remove</a>
the events used to say existing_event_attachment_attributes like page, but i tried updating the code. |
Ryan Bates
29 posts
|
The HTML looks correct. Are you certain the page model is behaving correctly? It’s very strange one model would behave differently than another. There must be some difference between the two. If you problem is with what is being saved to the database on edit, then start at the database SQL query which saves the attachment and work your way back. Check your log to see what queries and parameters are being sent in the request. And put “logger.debug …” tracers in your app to see if you are getting the file attachment data. This way you can find out exactly where the attachment file data is getting lost which should narrow down your problem. |
RyanL
8 posts
|
i will look through and try to back trace the data from the log. Thanks for the tip. It strange, the other data in event will be updated, so its calling the update action. Its so weird. page: event: |
RyanL
8 posts
|
interesting update on page sends the image here…. Also, i have thumbnails specified as content, thumb, and list, but the event update does not save them. It only lists the main file, unlike the page update, that saves all versions. |
Ryan Bates
29 posts
|
From what I can tell, the parameters sent to the update action look correct. Maybe something is wrong with how attachments are configured on the event model itself. Try adding attachments through script/console and see if it works. This way you take out the multi-model form complexity entirely. |
8 posts, 2 voices
