Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grab file path from upload

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 %>

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

like image 661
Max Avatar asked Feb 23 '23 13:02

Max


1 Answers

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
like image 74
fl00r Avatar answered Mar 07 '23 13:03

fl00r