upload files to the specified directory

13 views
Skip to first unread message

dhaval

unread,
May 10, 2007, 11:22:18 PM5/10/07
to rubyonra...@googlegroups.com
hello

Can you tell me how do i create a page that allows me to have a facility
by which the user can upload a file to the defined folder

pls provide the code for controller,model and view

thanks

dhaval

--
Posted via http://www.ruby-forum.com/.

Alex Wayne

unread,
May 11, 2007, 1:20:25 AM5/11/07
to rubyonra...@googlegroups.com
dhaval wrote:
> hello
>
> Can you tell me how do i create a page that allows me to have a facility
> by which the user can upload a file to the defined folder
>
> pls provide the code for controller,model and view
>
> thanks
>
> dhaval

Controller action:

def upload
File.open
"#{RAILS_ROOT}/uploads/#{params[:file].original_filename}", 'wb' do |f|
f.write(params[:file].read)
end
redirect_to :action => 'index'
end

View:

<% form_tag({:action => 'upload'}, {:multipart => true}) do %>
Upload a file:
<%= file_field_tag 'file' %>
<%= submit_tag 'Submit' %>
<% end %>

dhaval

unread,
May 11, 2007, 2:34:22 AM5/11/07
to rubyonra...@googlegroups.com
thanx a lot man :)
Reply all
Reply to author
Forward
0 new messages