我正在尝试使用示例代码上传文件。我没有收到任何编译错误,而是一条406 Not Acceptable
错误消息。这是什么意思?
发布请求:
Started POST "/files/upload" for 10.15.24.38 at 2012-06-22 21:18:11 -0400
Processing by FilesController#upload as HTML
Parameters: {"utf8"=>"â", "authenticity_token"=>"wfpBi3Y8KgmqitXrh4fZ3xfun73mWOfXiTQ+J7bdfWU=", "user_id"=>"231",
"button"=>"", "upload"=>{"datafile"=>"ws_1920x1080.jpg"}}
看法:
<%= form_tag files_upload_path, :remote => true, :method => :post, :multipart => true do %>
#The form has some other values too. I am keeping it short here.
<p>
<label for="upload_file">Select File</label> :
<%= file_field 'upload', 'datafile' %>
</p>
<% end %>
控制器:
def upload
#The controller has some other values too, that are not related to file upload.
if params[:datafile]
uploaded_io = params[:upload][:datafile]
File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'w') do |file|
file.write(uploaded_io.read)
end
end
if params[:user_id]
#do some extra stuff
end
respond_to do |format|
format.js
end
end
错误:
Completed 406 Not Acceptable in 2736ms (ActiveRecord: 3.2ms)