开发者

Rails: form input type and getting the filename

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 k开发者_StackOverflow中文版now 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.


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜