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.

Arnold Daniels
  • 16,516
  • 4
  • 53
  • 82
pvskisteak5
  • 4,162
  • 3
  • 24
  • 26

1 Answers1

2

I'm doing something similar to this, but instead of using Ruby to shorten the length, i'm using CSS. If the text is longer than it can fit within the span4 class of my div tag, it will add a ... at the end instead of wrapping to the next line.

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

So, in my view, I would have something like this:

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

and it would display similar to below.

enter image description here

kobaltz
  • 6,980
  • 1
  • 35
  • 52