Skip to content

Instantly share code, notes, and snippets.

@dimerman
Forked from fractaledmind/seeds.rb
Created May 15, 2024 04:40
Show Gist options
  • Save dimerman/5782ad8f5ab75ca1a659986ac87b6370 to your computer and use it in GitHub Desktop.
Save dimerman/5782ad8f5ab75ca1a659986ac87b6370 to your computer and use it in GitHub Desktop.
Example of simple file to centralize User management
users_file = Rails.root.join('storage', 'users.yml.erb')
if File.exist? users_file
users = YAML.load(ERB.new(File.read(users_file)).result)
User.insert_all(
users.map { |user| user.except("password") },
unique_by: :username
)
end
<%
def digest(username, password)
ActionController::HttpAuthentication::Digest.ha1(
{
username: username,
realm: Rails.application.credentials.auth_realm
},
password
)
end
%>
---
- username: spm
email: [email protected]
password: 'mypassword'
password_digest: <%= digest("spm", "mypassword") %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment