Upload files in directory

I use Rails 3.2.2 and i created a web application.
I want to upload files and save them in assets directory and save its
locations in DB.
how can i do that?

On 3 April 2012 10:42, Sayed G. Farag [email protected] wrote:

I use Rails 3.2.2 and i created a web application.
I want to upload files and save them in assets directory and save its
locations in DB.
how can i do that?

Start by googling for
rails file upload
Then when you see the options and have looked over them come back if
you need clarifications or recommendations.

Colin

I have already tried and saved the uploaded files in directory but Not
save it’s path in DB.
this is the error >> Couldn’t find Resource with ID=uploadFile.
this is my controller and view

def uploadFile
@text = params[:upload]
@file=@text[‘datafile’].original_filename

name = @file
directory = "public/data"
# create the file path
path = File.join(directory, name)
# write the file
File.open(path, "wb") { |f| f.write(@text['datafile'].read) }
redirect_to(:actions=>'new')

end

<%= form_tag ‘uploadFile’,:multipart => true %>

<%= select(:CatID, Resource.SubCategories.collect {|t| [ t.Name, t.ID ]}, :style=>"width: 400px") %>

<%= label "labeltext","Name" %> <%= text_field :Name, :style=>"width:400px;" %>

<%= label "labelDes","Description" %> <%= text_area :Description, :style=>"width:400px;height:100px" %>

Select File : <%= file_field 'upload', 'datafile'%> <%= submit_tag "Upload" %>