![](/img/trans.png)
[英]Rails: Generate Unique Random Number for populating a CSS class String How To?
[英]How to generate a random string in rails
在我的表格中,我想為以下字段生成隨機字符串
f.input :lti_api_key, label: "LTI API KEY"
f.input :lti_api_secret, label: "LTI API SECRET"
我怎樣才能做到這一點? 請幫我...
您可以這樣輸入f.input
<%= f.text_field :name, id: :bug_name, value: "#{SecureRandom.hex(64)}" %>
您好,您可以這樣做:
require 'securerandom'
SecureRandom.hex(64)
看一下string_pattern gem項目: https : //github.com/MarioRuiz/string_pattern
要安裝它: gem install string_pattern
這是一個使用示例:
require 'string_pattern'
# four characters. optional: capitals and numbers, required: lower
"4:XN/x/".gen # aaaa, FF9b, j4em, asdf, ADFt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.