1

I am using Jasny's Bootstrap plugin for file uploads in a rails app that is using paperclip. It is working fine, but I would like to truncate the file name that is previewed before uploading.

After selecting a file, I would like the file upload preview text to say something like 'example_fil...' instead of 'example_file_for_practice.jpg'.

Are there any techniques for doing this either in the view (doubtful) or in Bootstrap/Jasny?

Also, I know someone is going to tell me to check out the jquery file upload plugin - it is pretty awesome! I'd like to try to solve this problem before moving on, though.

4

1 回答 1

2

我正在做类似的事情,但我没有使用 Ruby 来缩短长度,而是使用 CSS。如果文本的长度超出了我的 div 标签的 span4 类所能容纳的长度,它将...在末尾添加 a 而不是换行到下一行。

li .text{
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

所以,在我看来,我会有这样的事情:

<li class="text"><%= video.name %></li>

它会显示类似于下面的内容。

在此处输入图像描述

于 2013-03-12T15:53:44.453 回答