本文介绍了如何在Rails Contoller中获取上传文件的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<%= file_field 'upload' %>
在我的控制器中,根据建议,如果我给出以下内容
In my controller, if I give the following, based on suggestions
filename=params[:upload]
@result=filename.original_filename
我得到了.
undefined method `original_filename' for
#<ActionController::Parameters:0x002b6c396e44b8>
注意:我没有使用表格.Rails版本是4.0.2
Note: I am not using form. Rails version is 4.0.2
推荐答案
使用以下代码获取文件名:
Use the following code in order to get the filename:
params[:file].original_filename
这篇关于如何在Rails Contoller中获取上传文件的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!