当前ruby1.9.3 rails 3.2.8,流行的文件上传插件是[url=https://github.com/thoughtbot/paperclip]paperclip[/url]和[url=https://github.com/jnicklas/carrierwave]carrierwave[/url]
然而,简单的这是需要上传个文件的话,可以用更容易的办法
然而,简单的这是需要上传个文件的话,可以用更容易的办法
<%= 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