前提・実現したいこと
SNSのユーザー名を使い、user/usernameという形でURLを据え置きたい。
初期データとしてURLのユーザーIDを乱数にしたい。
発生している問題・エラーメッセージ
ruby
1#db/seeds.rb 2 3require "securerandom" 4 5User.create!(name: "User1", 6 username: "imer_test", 7 email: "example@example.com", 8 password: "foobar", 9 password_confirmation: "foobar", 10 admin: true) 11 1299.times do |n| 13 name = Faker::Name.name 14 username = SecureRandom.urlsafe_base64(10) 15 email = "example-#{n+1}@example.com" 16 password = "password" 17 User.create!(name: name, 18 email: email, 19 password: password, 20 password_confirmation: password) 21end
usernameはtwitterでいう@imer_testというユーザー名を表します。
このusernameを乱数で生成するためにSecureRandom.urlsafe_base64(10)を使用したのですが、DBのカラムがnullになってしまいます。
rubyの標準機能が.rbの拡張子で動かないのはどうにも納得がいかず、かといって解決手段が見当たらないのでどうしたらいいかをここでお聞きしたいと思います。よろしくお願いします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/18 02:14
2020/08/18 02:16 編集
2020/08/18 02:21