# \[TIPS\] File\_column plugin and multiple file uploads

**URL:** <https://www.ruby-forum.com/t/tips-file-column-plugin-and-multiple-file-uploads/58740>\
**Category:** Rails\
**Created:** [April 25, 2006, 2:30pm UTC](https://www.ruby-forum.com/t/tips-file-column-plugin-and-multiple-file-uploads/58740 "2006-04-25T14:30:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [April 25, 2006, 2:30pm UTC](https://www.ruby-forum.com/t/tips-file-column-plugin-and-multiple-file-uploads/58740/1 "2006-04-25T14:30:58Z")

</div>

No…i am not a full time rails developer…i code in pl/sql for paying  
my  
bills…and i am just working on a pet project…so i had some trouble  
in  
doing…what i specify in the subject…now somehow i solved this  
problem…so those interested can look at the code at:

> **[file\_column and how the fuck it handles multiple files?](https://hemant.wordpress.com/2006/04/25/file_column-and-how-the-fuck-it-handles-multiple-files/)**
>
> Handling multiple files with file\_column plugin can be quite nifty and the most of the time its lack of documentation that makes thing challenging. So here goes my code, without much talk:

I write this mail and [blog]post…so that Amy doesn’t call me a Help  
monster. 🙂

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [April 25, 2006, 3:08pm UTC](https://www.ruby-forum.com/t/tips-file-column-plugin-and-multiple-file-uploads/58740/2 "2006-04-25T15:08:33Z")

</div>

I read your blog post. You seem to be complicating things. It is  
perfectly valid to have multiple fields in the same table use  
file\_column.

Why not just say in your model

file\_column :picture\_1  
file\_column :picture\_2  
…

and then simply let file\_column work like it’s supposed to, complete  
with file\_column\_field helpers?

hemant kumar wrote:

> No…i am not a full time rails developer…i code in pl/sql for paying  
> my  
> bills…and i am just working on a pet project…so i had some trouble  
> in  
> doing…what i specify in the subject…now somehow i solved this  
> problem…so those interested can look at the code at:
> 
> [file\_column and how the fuck it handles multiple files? | Oh Lame saint](http://hemant.wordpress.com/2006/04/25/file_column-and-how-the-fuck-it-handles-multiple-files/)
> 
> I write this mail and [blog]post…so that Amy doesn’t call me a Help  
> monster. 🙂

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [April 25, 2006, 3:20pm UTC](https://www.ruby-forum.com/t/tips-file-column-plugin-and-multiple-file-uploads/58740/3 "2006-04-25T15:20:46Z")

</div>

But then i thought in “file\_column :picture”, picture must be a column  
in  
the table, right?  
and i have only one column to store filenames in my table…correct me,  
if  
i am wrong?

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [April 25, 2006, 3:27pm UTC](https://www.ruby-forum.com/t/tips-file-column-plugin-and-multiple-file-uploads/58740/4 "2006-04-25T15:27:02Z")

</div>

Also is it a good idea to predefine, the number of files that i can  
upload?..though my current code relies on that…but i am gonna change  
that…and if in the model class itself i specify how many columns i  
need  
then i am stuck there, right?

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [April 25, 2006, 3:55pm UTC](https://www.ruby-forum.com/t/tips-file-column-plugin-and-multiple-file-uploads/58740/5 "2006-04-25T15:55:07Z")

</div>

If I have a model that requires a variable # of images, I usually just  
create an additional table called model\_images, and then add a :has\_many  
=\>  
:model\_images (with a corresponding belongs\_to :model in the images  
model)  
to my model. That way if you need to have metadata about the images  
(captions, or whatever), you can store that in the images table. This  
way  
your # of images is unlimited, and you can just add a :file\_column  
:image or  
whatever to your images table.

Works for me…

Matt

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [April 25, 2006, 3:58pm UTC](https://www.ruby-forum.com/t/tips-file-column-plugin-and-multiple-file-uploads/58740/6 "2006-04-25T15:58:26Z")

</div>

Whoops… Too early… I meant “:file\_column :image to your images  
model”

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [April 25, 2006, 4:07pm UTC](https://www.ruby-forum.com/t/tips-file-column-plugin-and-multiple-file-uploads/58740/7 "2006-04-25T16:07:46Z")

</div>

yeah…got it…thatz a cool idea…but right now basically pictures  
table  
is like your model\_images table…and i am storing all the metadata,  
like Tags and all that in this table itself…

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [April 25, 2006, 4:23pm UTC](https://www.ruby-forum.com/t/tips-file-column-plugin-and-multiple-file-uploads/58740/8 "2006-04-25T16:23:52Z")

</div>

Yes, you would need a varchar/:string column in your table for each  
file\_column.

Sorry, your action name and the post titles confused me. This looks like  
a method just for adding multiple new image records from a single form.

I gather that mutliple instances of

\<%= file\_column\_field "picture[], “filename” -%\>

in a single form doesn’t work, eh?

hemant kumar wrote:

> But then i thought in “file\_column :picture”, picture must be a column  
> in  
> the table, right?  
> and i have only one column to store filenames in my table…correct me,  
> if  
> i am wrong?
