# Getting images from array

**URL:** <https://www.ruby-forum.com/t/getting-images-from-array/142681>\
**Category:** Rails\
**Created:** [July 10, 2008, 10:54am UTC](https://www.ruby-forum.com/t/getting-images-from-array/142681 "2008-07-10T10:54:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![torso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/34f0e0/32.png) [@torso](https://www.ruby-forum.com/u/torso)\
**Post date:** [July 10, 2008, 10:54am UTC](https://www.ruby-forum.com/t/getting-images-from-array/142681/1 "2008-07-10T10:54:24Z")

</div>

Hi

I have this kind of code source for uplaodin an image.  
from controller:  
def uploadFile  
@text = “File has been uploaded successfully”

```
post = DataFile.save(params[:upload])
render :text => @text

```

end

from model:  
def self.save(upload)  
name = upload[‘datafile’].original\_filename  
directory = “public/data”  
#Creating the file path  
path = File.join(directory, name)  
#write the file  
File.open(path,“wb”){ |f| f.write(upload[‘datafile’].read) }  
end

But variable upload should be sent on array in new version. If i wan’t  
to go through that array what is the easist way.  
Do i have to do just loop. I am newbie on rails so i am lit bit  
confused about the dynamic variables.

---

<div class="post-metadata">

**Author:** ![torso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/34f0e0/32.png) [@torso](https://www.ruby-forum.com/u/torso)\
**Post date:** [July 10, 2008, 11:25am UTC](https://www.ruby-forum.com/t/getting-images-from-array/142681/2 "2008-07-10T11:25:40Z")

</div>

[http://clarkware.com/cgi/blosxom/2007/02/24](http://clarkware.com/cgi/blosxom/2007/02/24), this might help.

and yes, if you want to accept an array instead of a variable, then  
you would need to loop through it so that you can save many images;

== controller

def upload\_file # please don’t camel case  
images = params[:images]  
#do your stuff  
Model.save images  
end

=== model

def self.save images  
images.each do |image|  
# save files  
end  
end

But i strongly suggest you do it the rails way, as the files will be  
much easier to manage.

---

<div class="post-metadata">

**Author:** ![torso](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/34f0e0/32.png) [@torso](https://www.ruby-forum.com/u/torso)\
**Post date:** [July 10, 2008, 6:21pm UTC](https://www.ruby-forum.com/t/getting-images-from-array/142681/3 "2008-07-10T18:21:57Z")

</div>

Thanks for replay. I have to tried it by rails way.
