# Attachment\_fu and form\_tag for multiple models?

**URL:** <https://www.ruby-forum.com/t/attachment-fu-and-form-tag-for-multiple-models/128087>\
**Category:** Rails\
**Created:** [February 4, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/attachment-fu-and-form-tag-for-multiple-models/128087 "2008-02-04T22:37:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [February 4, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/attachment-fu-and-form-tag-for-multiple-models/128087/1 "2008-02-04T22:37:07Z")

</div>

hi, i’ve got a page where i’m trying to save the user’s profile  
information and an image of the user, but i’m having trouble with using  
attachment\_fu and the form\_tag method.

now i know attachment\_fu isn’t designed for form\_tag but am really  
hoping someone has a solution for this as frankly i’m stumped.

here’s the form\_tag part in the view…

\<% form\_tag( { :action =\> “add\_profile” }, { :multipart =\> true }) do %\>

\<%= file\_field\_tag ‘image’, :uploaded\_data %\>

\<%= text\_area :profile, :body, :cols =\> 25, :rows =\> 6 %\>

\<%= submit\_tag ‘Submit’ %\>

\<% end -%\>

and in the add\_profile method…

def add\_profile  
return unless request.post?

@image = Image.new(params[:image])  
@image.user\_id = self.current\_user.id  
@image.default = true #set it to be the default photo for the user

@profile = Profile.find(self.current\_user.id)  
@profile.update\_attributes(params[:profile])  
redirect\_to :action =\> ‘profile’  
end

looks like it should work and the profile part is being saved but no  
image is being uploaded.

any ideas?

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [February 4, 2008, 11:23pm UTC](https://www.ruby-forum.com/t/attachment-fu-and-form-tag-for-multiple-models/128087/2 "2008-02-04T23:23:43Z")

</div>

On Feb 4, 2008 1:37 PM, John G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<% form\_tag( { :action =\> “add\_profile” }, { :multipart =\> true }) do %\>  
> and in the add\_profile method…  
> redirect\_to :action =\> ‘profile’  
> end
> 
> looks like it should work and the profile part is being saved but no  
> image is being uploaded.

Try saving the @image instance.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![softf5ajivanet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@softf5ajivanet](https://www.ruby-forum.com/u/softf5ajivanet)\
**Post date:** [February 5, 2008, 12:13am UTC](https://www.ruby-forum.com/t/attachment-fu-and-form-tag-for-multiple-models/128087/3 "2008-02-05T00:13:35Z")

</div>

ugh, thanks Rick,

added a save method and it worked fine.

i changed the filetag to…

\<%= file\_field :image, :uploaded\_data %\>

and in the controller added the save call…

@image.save

😉
