Uploading files

Hi there.

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

Im a beginner

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

((ignore the Rmagik stuff in the meantime))

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.

Compare and review Rails hosting

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

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

On 1/16/07, Emil K. [email protected] 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