Grab file path from upload
I have an RoR script that when given the f开发者_开发问答ile 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 %>
The controller for the create area is:
$XML_FILE = params[:my_file]
routers = Router.new
@title = routers.overall_setup
if @title == "Everything worked" then
redirect_to "/"
end
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
where params[:setup][:my_file]
is your file_filed
name in the form
Rails 3
path = params[:setup][:my_file].path
精彩评论