upload files to the specified directory

已查看 13 次
跳至第一个未读帖子

dhaval

未读,
2007年5月10日 23:22:182007/5/10
收件人 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

未读,
2007年5月11日 01:20:252007/5/11
收件人 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

未读,
2007年5月11日 02:34:222007/5/11
收件人 rubyonra...@googlegroups.com
thanx a lot man :)
回复全部
回复作者
转发
0 个新帖子