-
Notifications
You must be signed in to change notification settings - Fork 5
/
create_user.rb
37 lines (31 loc) · 919 Bytes
/
create_user.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# create_user.rb
require_relative 'config/environment'
def prompt(message)
print "#{message}: "
gets.chomp
end
email = prompt("Enter email")
password = prompt("Enter password")
username = prompt("Enter username (or leave blank to use email prefix)")
full_name = prompt("Enter full name")
tags = prompt("Enter tags (comma-separated)")
avatar = prompt("Enter avatar URL")
banner = prompt("Enter banner URL")
description = prompt("Enter description")
username = email.split('@').first if username.strip.empty?
tags = tags.split(',').map(&:strip).to_json unless tags.strip.empty?
user = User.new(
email: email,
password: password,
username: username,
full_name: full_name,
tags: tags || '[]',
avatar: avatar,
banner: banner,
description: description
)
if user.save
puts "User #{user.username} created successfully."
else
puts "Error creating user: #{user.errors.full_messages.join(', ')}"
end