问题描述
我有一个 RoR 脚本,当给定 XML 文件的文件路径时,它会解析它.我希望能够使用 GUI 找到该文件,然后允许我的脚本运行.这是我在视图中的内容:
I have an RoR script that when given the file path for an XML file, will parse it. I want to be able to find the file with the GUI, and then allow for my script to run. Here's what I have in the view:
<%= form_for :setup, :html=>{:multipart=>true}, :url=>{action=>"create"} do |f| %>
<%= f.file_filed :my_file %>
<%= f.submit "Upload" %>
<% end %>
创建区域的控制器是:
$XML_FILE = params[:my_file]
routers = Router.new
@title = routers.overall_setup
if @title == "Everything worked" then
redirect_to "/"
end
基本上从这里开始,您如何找出文件路径?我知道一旦可以将正确的文件路径放置到 $XML_FILE 中,其余代码就可以工作
Basically from here, how do you snag the file path out? I know that once the correct file path can be placed to $XML_FILE that the rest of the code works
推荐答案
提交表单后,您可以通过以下方式找到上传的文件:
After you've submited a form you can find upploaded file this way:
path = params[:setup][:my_file][:tempfile].path
其中 params[:setup][:my_file]
是您在表单中的 file_filed
名称
where params[:setup][:my_file]
is your file_filed
name in the form
path = params[:setup][:my_file].path
这篇关于从上传中获取文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!