views:

35

answers:

2

Hi,

As I am using Ruby on Rails to build an application, which only runs locally, I am lost in the woods (a nuby without a compass). I have a simple MVC application and my view is missing one thing I could really use. I want to select a local file just to retrieve it's filename. I know it's relatively easy to use the form tag helpers for uploading:

<%= file_field 'upload', 'datafile' %></p>

I wonder how I could get the filename from the selected file, without uploading the file.

A: 

Not sure if you can do this without uploading the file.

If the form isn't set to multipart, the file won't be uploaded, just not sure what data is sent. But ... have a look in your logs and see what parameters are being passed with the request ... you might see the file name as a string.

Toby Hede
+1  A: 

You could use jquery. Just do something like

var name = $('my_input_id').val();
alert(name);

if you have to pass the name to your application you could just use jquery post to your controller. Your controller should be able to understand the format js (hint: respond_to).

VP
Thanks! Never even knew the .val() method, kind of new to JQuery!
Shyam