在 Ruby on Rails 3.2.6 中从 Paperclip 生成的文件中删除问号 [英] Remove question mark from Paperclip-generated files in Ruby on Rails 3.2.6
问题描述
我正在使用 Paperclip-FFMEG 将视频文件上传到我的开发环境(并最终在我的项目投入生产时上传到本地服务器).
I'm using Paperclip-FFMEG to upload video files to my development environment (and, eventually, to a local server when my project goes into production).
上传视频时,文件名默认如下:
When videos are uploaded, the filename is, by default, as follows:
/system/modelnames/paperclipnames/.../mynewfile.mp4?xxxxxxxxxx
我认为问号后面的 10 位数字是时间戳.
I believe the 10 digit figure after the questionmark is a timestamp.
但是,我将用来播放视频的播放器不喜欢在文件附件之后有任何内容 - 所以我想在将 URL 传递到播放器之前去除问号和后面的时间戳.
However, the player I will be using to play the videos doesn't like to have anything after the file attachment - so I would like to strip the questionmark, and the timestamp after it, before passing the URL into the player.
我尝试使用以下 Ruby(我认为)条带函数:
I tried to use the following Ruby (I think) strip function:
temp_variable = model.paperclipattribute.url(:blah).strip('?')[0]
然而,Rails 抛出了一个错误:
However, Rails throws up an error:
wrong number of arguments(1 for 0)
我认为我做错了吗?还有其他解决方案吗?我不想完全关闭时间戳,因为我只需要在这种情况下这样做.
I take it I'm doing this wrong? Any other solutions? I don't want to switch off timestamps entirely, as I only need to do so in this situation.
谢谢!
推荐答案
如果您想对给定的附件在任何地方执行此操作且无需传递额外参数,您可以设置 use_timestamp
在模型中调用 has_attached_file
方法时的选项.因此,以 Paperclip README 中给出的示例为基础:
If you want to do this everywhere for a given attachment and without the need to pass the extra parameter, you can set the use_timestamp
option when calling the has_attached_file
method in your model. So, to build on the example given in the Paperclip README:
has_attached_file :avatar,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:default_url => "/images/:style/missing.png",
:use_timestamp => false
这篇关于在 Ruby on Rails 3.2.6 中从 Paperclip 生成的文件中删除问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!