说rails文件上传

阅读更多
当前ruby1.9.3 rails 3.2.8,流行的文件上传插件是 paperclip和 carrierwave

然而,简单的这是需要上传个文件的话,可以用更容易的办法
<%= 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

你可能感兴趣的:(ruby,rails,paperclip,upload)