0

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...

3
  • 1
    What do you mean random strings? Give us an example. Commented Jul 5, 2017 at 14:03
  • i just want to generate a string which is random & unique. Commented Jul 6, 2017 at 0:28
  • something like this "2d9492324049139257ac65ff49e97b961d6a657b6f6fa1d144d5af66e364afcb" Commented Jul 6, 2017 at 0:29

3 Answers 3

4

You can have your f.input as such

<%= f.text_field :name, id: :bug_name, value: "#{SecureRandom.hex(64)}" %>
Sign up to request clarification or add additional context in comments.

Comments

1

Hello you can do that:

require 'securerandom'
SecureRandom.hex(64)

Comments

-2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.