欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

说rails文件上传 rubyrailspaperclipupload 

程序员文章站 2024-03-19 19:43:52
...
当前ruby1.9.3 rails 3.2.8,流行的文件上传插件是paperclipcarrierwave

然而,简单的这是需要上传个文件的话,可以用更容易的办法
<%= form_tag({:action => :upload}, :multipart => true) do %>
  <%= file_field_tag 'picture' %>
<% end %>
 
<%= form_for @person do |f| %>
  <%= f.file_field :picture %>
<% end %>

def upload
  uploaded_io = params[:person][:picture]
  File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'w') do |file|
    file.write(uploaded_io.read)
  end
end