Skip to content

Instantly share code, notes, and snippets.

@AhmedNadar
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AhmedNadar/9d177a59a701a96d48a3 to your computer and use it in GitHub Desktop.
Save AhmedNadar/9d177a59a701a96d48a3 to your computer and use it in GitHub Desktop.
Create Admin Users with Active Admin using email only!
# As admin you can create other Admin Users with thier email only where password link is sent via email
# 1- Gemfile
gem 'devise'
gem 'activeadmin', github: 'gregbell/active_admin'
# 2- Install Devise then Active Admin
rails g devise:install
rails g active_admin:install
# You might see other instructions inthe terminal, just follow them
# Type Yes for override user modle
# 3- migrate
rake db:migrate
# 4- Update Admin User form: 'app/admin/admin_user.rb'
# Basicly comment password and confirm_password inputs
form do |f|
f.inputs "Admin Details" do
f.input :email
end
f.actions
end
# 5- Admin can created by email only without a password
# creat_after sends email to the Admin's email with a link to create a password
after_create { |admin| admin.send_reset_password_instructions }
def password_required?
new_record? ? false : super
end
# 6- Then we need to update our mailr default URL in development here, 'config/environments/development.rb'
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
# For sure send email will fail, because we need to setup a Mailer for the email to be sent,
# check Action Mailer (http://guides.rubyonrails.org/action_mailer_basics.html)
# But we can view the email content on the terminal.
# Example below:
# Rendered devise/mailer/reset_password_instructions.html.erb (2.7ms)
# Devise::Mailer#reset_password_instructions: processed outbound mail in 53.7ms
# Sent mail to someone@mail.com (56.9ms)
# Date: Thu, 17 Jul 2014 10:42:36 +0000
# From: please-change-me-at-config-initializers-devise@example.com
# Reply-To: please-change-me-at-config-initializers-devise@example.com
# To: someone@mail.com
# Message-ID: <53c80bc6c41040246f2@purple-car-1804.mail>
# Subject: Reset password instructions
# Mime-Version: 1.0
# Content-Type: text/html;
# charset=UTF-8
# Content-Transfer-Encoding: 7bit
# <p>Hello someone@mail.com!</p>
# <p>Someone has requested a link to change your password. You can do this through the link below.</p>
# <p><a href="http://localhost:3000/admin/password/edit?reset_password_token=yzJaaaefefsofskjsddfdfdkNss">Change my password</a></p>
# <p>If you didn't request this, please ignore this email.</p>
# <p>Your password won't change until you access the link above and create a new one.</p>
# It works :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment