在我正在开发的Ruby on Rails应用程序中,我允许用户上传文件,并希望为这些文件提供一个简短的随机字母数字名称.(例如'g7jf8'或'3bp76').做这个的最好方式是什么?
我想从原始文件名和时间戳生成哈希/加密字符串.然后查询数据库以仔细检查它不存在.如果是,请生成另一个并重复.
我用这种方法看到的问题是,如果重复字符串有很高的可用性,它可能会增加很多数据库负载.
我最近从使用Ubuntu系统Ruby转向使用RVM.当我运行时foreman start,无论命令在我的Procfile中是什么,我都会得到一个未找到的错误.
我目前的Procfile是:
web: bundle exec unicorn -p $PORT -c ./unicorn.rb
Run Code Online (Sandbox Code Playgroud)
所以错误是:
/home/timmillwood/.rvm/gems/ruby-1.9.3-p327/gems/foreman-0.60.2/bin/foreman-runner: 41: exec: bundle: not found
Run Code Online (Sandbox Code Playgroud)
which foreman 回报
/home/timmillwood/.rvm/gems/ruby-1.9.3-p327/bin/foreman
Run Code Online (Sandbox Code Playgroud)
which bundle 回报
/home/timmillwood/.rvm/gems/ruby-1.9.3-p327/bin/bundle
Run Code Online (Sandbox Code Playgroud)
输出来自rvm info:
ruby-1.9.3-p327:
system:
uname: "Linux ubuntu 3.5.0-19-generic #30-Ubuntu SMP Tue Nov 13 17:48:01 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux"
system: "ubuntu/12.10/x86_64"
bash: "/bin/bash => GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)"
zsh: " => not installed"
rvm:
version: "rvm 1.17.3 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]"
updated: …Run Code Online (Sandbox Code Playgroud)