Ruby on Rails Wednesday, April 4, 2012

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 %>

<div class="field">
<%= select(:CatID, Resource.SubCategories.collect {|t| [ t.Name,
t.ID ]}, :style=>"width: 400px") %><br/><br/>
<%= label "labeltext","Name" %>
<%= text_field :Name, :style=>"width:400px;" %> <br/><br/>
</div>
<div class="field">
<%= label "labelDes","Description" %>
<%= text_area :Description, :style=>"width:400px;height:100px" %>
<br/> <br/>
</div>
Select File : <%= file_field 'upload', 'datafile'%>
<%= submit_tag "Upload" %>


On Apr 4, 9:29 am, Colin Law <clan...@googlemail.com> wrote:
> On 3 April 2012 10:42, Sayed G. Farag <sayed.gama...@gmail.com> 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

--
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@googlegroups.com.
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.

No comments:

Post a Comment