Uploading files


#1

Hi there.

Is there anyone, who can direct me to a site, that explains how to
upload a file via RoR

Im a beginner


#2

Emil K. wrote:

Hi there.

Is there anyone, who can direct me to a site, that explains how to
upload a file via RoR

Im a beginner

look up file_column:

http://www.kanthak.net/opensource/file_column/

i think there are other things out there (in fact, maybe even better)
but i think this quite basic and good enough.
hth,

s


#3

((ignore the Rmagik stuff in the meantime))


#4

Other options are:

acts_as_attachment:
http://technoweenie.stikipad.com/plugins/show/Acts+as+Attachment

or

flex_image: http://beautifulpixel.textdriven.com/

Kind regards,

Nick S.

http://railshostinginfo.com
Compare and review Rails hosting


#5

You can also put this kind of stuff in your controller (for example) or
for DRY put it in your model…

@file = params[:image][:img]
if @file.original_filename.length > 0
  filename = session[:dirname] + "/" + @file.original_filename
  File.open(filename, "w")  { |f| f.write(@file.read) }
end
redirect_to :action => "index"

Emil K. wrote:

Hi there.

Is there anyone, who can direct me to a site, that explains how to
upload a file via RoR

Im a beginner


#6

Nicolas B. wrote:

You can also put this kind of stuff in your controller (for example) or
for DRY put it in your model…

@file = params[:image][:img]
if @file.original_filename.length > 0
  filename = session[:dirname] + "/" + @file.original_filename
  File.open(filename, "w")  { |f| f.write(@file.read) }
end
redirect_to :action => "index"

DRY ?? What is this ?

  • Emil

#7

On 1/16/07, Emil K. removed_email_address@domain.invalid wrote:

redirect_to :action => "index"

DRY ?? What is this ?

DRY means Don’t Repeat Yourself, a common mantra for rails developers.
For instance, using one of the above mentioned plugins means this
will probably be taken care of for you.

If you’re on rails 1.2 and were looking at acts_as_attachment, I’d
suggest my refactored update attachment_fu. It has an #uploaded_data
accessor that handles the above code in your model.


Rick O.
http://weblog.techno-weenie.net
http://mephistoblog.com