# Attachment\_fu with hidden\_field

**URL:** <https://www.ruby-forum.com/t/attachment-fu-with-hidden-field/138817>\
**Category:** Rails\
**Created:** [May 28, 2008, 1:39am UTC](https://www.ruby-forum.com/t/attachment-fu-with-hidden-field/138817 "2008-05-28T01:39:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [May 28, 2008, 1:39am UTC](https://www.ruby-forum.com/t/attachment-fu-with-hidden-field/138817/1 "2008-05-28T01:39:51Z")

</div>

hey i am using attachment\_fu for photo purposes and i am trying to  
pass a hidden value to be stored when a photo is uploaded. i am not  
sure how to pass this value. this is my intuitive attempt, but its  
not working:

\<% form\_for(:photo, :url =\> photos\_path, :html =\> { :multipart =\>  
true }) do |f| -%\>

```
    <%= f.file_field :uploaded_data, :other => params[:id] %><br/>
    <%= f.hidden_field :other => params[:id] %><br/>

<%= submit_tag 'Create' %>

```

\<% end -%\>

as you can see, i want to be able to store the value in the id params  
hash into the database column other. any ideas how to do this?  
thanks, dave

---

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [May 28, 2008, 1:51am UTC](https://www.ruby-forum.com/t/attachment-fu-with-hidden-field/138817/2 "2008-05-28T01:51:33Z")

</div>

\<% form\_for(:photo, :url =\> photos\_path, :html =\> { :multipart =\>  
true }) do |f| -%\>  
\<%= f.file\_field :uploaded\_data%\>  
  
\<%= f.hidden\_field :other, :value=\> params[:id] %\>  
  
\<%= submit\_tag ‘Create’ %\>  
\<% end -%\>

assuming the request parameter “id” is what you want to go into the  
“other” field.

Though it would make more sense either to populate that other field in  
the controller  
on create or in the controller method that sets up and renders the  
form like so:

def new  
@photo = Photo.build(:other=\>“whatever I want other to be”)  
end

then in the form, just

\<% form\_for(:photo, :url =\> photos\_path, :html =\> { :multipart =\>  
true }) do |f| -%\>  
\<%= f.file\_field :uploaded\_data%\>  
  
\<%= f.hidden\_field :other %\>  
  
\<%= submit\_tag ‘Create’ %\>  
\<% end -%\>

---

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [May 28, 2008, 1:55am UTC](https://www.ruby-forum.com/t/attachment-fu-with-hidden-field/138817/3 "2008-05-28T01:55:39Z")

</div>

sweet, works great. thanks.
