简体   繁体   中英

How to generate a random string in rails

In my form i want to generate random strings for the following fields

  f.input :lti_api_key, label: "LTI API KEY"
    f.input :lti_api_secret, label: "LTI API SECRET"

how can i do that? Please help me...

您可以这样输入f.input

<%= f.text_field :name, id: :bug_name, value: "#{SecureRandom.hex(64)}" %>

Hello you can do that:

require 'securerandom'
SecureRandom.hex(64)

Take a look at the string_pattern gem project: https://github.com/MarioRuiz/string_pattern

To install it: gem install string_pattern

This is an example of use:

require 'string_pattern'
# four characters. optional: capitals and numbers, required: lower
"4:XN/x/".gen    # aaaa, FF9b, j4em, asdf, ADFt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM