Generic-user-small 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][...][...]

I wasn't sure if it was a syntax error on my part or rails wanting to be buddy buddy with all the helpers, accidentally calling the page model's new_attachment_attribute instead of event's.

Thanks

 
Generic-user-small 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: />Tmp/CGI258-4>}}

but events say

existing_attachment_attributes”=>{“456”=>{“uploaded_data”=>#<file: />Tmp/CGI258-9>}}

how do get the params to say event => .....

 
Ryan_bates_cropped_small Ryan Bates 29 posts

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.

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.

 
Generic-user-small 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_cropped_small 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.

 
Generic-user-small 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:
Parameters: {“commit”=>”Update”, “authenticity_token”=>”...”, “_method”=>”put”, “action”=>”update”, “id”=>”2-advertising”, “controller”=>”admin/pages”, “page”=>{“body”=>”Adveritsing\r\n--—”, “title”=>”Advertising”, “existing_attachment_attributes”=>{“396”=>{“uploaded_data”=>”“}}}}

event:
Parameters: {“commit”=>”Update”, “authenticity_token”=>”...”, “_method”=>”put”, “event”=>{“event_info(2i)”=>”7”, “name”=>”hello world”, “event_info(3i)”=>”11”, “event_info(4i)”=>”10”, “event_info(5i)”=>”30”, “description”=>”Hello lovely World! This is a test!”, “existing_attachment_attributes”=>{“426”=>{“uploaded_data”=>”“}, “421”=>{“uploaded_data”=>”“}}, “featured_event”=>”1”, “event_info(1i)”=>”2008”}, “action”=>”update”, “id”=>”4-hello-world”, “controller”=>”admin/events”}

 
Generic-user-small RyanL 8 posts

interesting update on page sends the image here….
"uploaded_data"=>#<File:/var/folders/Ue/UeM9uAYmF+yAl5bA9Zo1OU+++TI/-Tmp-/CGI1703-4>}}
update on edit sends it here ….
"uploaded_data"=>#<File:/var/folders/Ue/UeM9uAYmF+yAl5bA9Zo1OU+++TI/-Tmp-/CGI1703-10>
but somehow its not getting written. The problem has to be with events.

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_cropped_small 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