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.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
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.
On Jul 10, 9:53 am, torso
<petteri.torsso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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.
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thanks for replay. I have to tried it by rails way. On 10 heinä, 12:23, "\"Wolas!\"" <jcpen...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > > On Jul 10, 9:53 am,torso<petteri.torsso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---