I''m getting very confused trying to use attachment_fu, but i''m sure the answer is simple to one of you... I have a model called ''MusicService'', which has a logo associated with it. Logos have been set up to belong_to :music_service, and music_service has_one :logo. Logo is also set up to be an attachment, with has_attachment and the usual parameters. So far so good. On the edit page for music_service is where i''m having problems - along with all the other fields for music_service i have a file_field for the logo file. Whereas the other fields write into a params field called ''name'', ''address'' etc, the file_field is writing into :uploaded_data. When i submit the form, the ''update'' controller action is called. How do i deal with :uploaded_data in the controller? I''m using attachment_fu elsewhere, where i have a form to edit a single attachment object, and that works fine, it''s just incorporating it into a larger form for a different model that''s got me snarled up. Any suggestions? thanks max -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1/28/08, Max Williams <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I''m getting very confused trying to use attachment_fu, but i''m sure the > answer is simple to one of you... > > I have a model called ''MusicService'', which has a logo associated with > it. Logos have been set up to belong_to :music_service, and > music_service has_one :logo. Logo is also set up to be an attachment, > with has_attachment and the usual parameters. So far so good. > > On the edit page for music_service is where i''m having problems - along > with all the other fields for music_service i have a file_field for the > logo file. Whereas the other fields write into a params field called > ''name'', ''address'' etc, the file_field is writing into :uploaded_data. > When i submit the form, the ''update'' controller action is called. How > do i deal with :uploaded_data in the controller? > > I''m using attachment_fu elsewhere, where i have a form to edit a single > attachment object, and that works fine, it''s just incorporating it into > a larger form for a different model that''s got me snarled up. > > Any suggestions? > thanksDo you have the file_field inside a fields_for block in your view? something like. <% form_for @music_service, :html => {:multipart => true}) do |f| %> ... <% f.fields_for :logo, @music_service.logo do |logo| %> <%= logo.file_field "uploaded_data" %> <% end %> .... <% end %> Note the :html => {:multipart => true} on the outer form_for, it''s important. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rick Denatale wrote:> > <% form_for @music_service, :html => {:multipart => true}) do |f| %> > ... > <% f.fields_for :logo, @music_service.logo do |logo| %> > <%= logo.file_field "uploaded_data" %> > <% end %> > .... > <% end %>Ah...so that''s how you do nested forms! Nice one, that was what i was stuck on i think. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks a lot.. I was searching for the exact same thing... But if you are using this form for creating a New file upload, you have to instantiate the nested object too. example - for the code given above> > <% form_for @music_service, :html => {:multipart => true}) do |f| %> > ... > <% f.fields_for :logo, @music_service.logo do |logo| %> > <%= logo.file_field "uploaded_data" %> > <% end %> > .... > <% end %>In the controllers new method/action you should put in a line @music_service = MusicService.new # there by default @music_service.logo = Logo.new # Add this to avoid an error related to new_record? -- Posted via http://www.ruby-forum.com/.