Trestle
Add an admin back-end using the Trestle gem
Used 48 times
S
Sam Pohlenz
Usage
Installs the Trestle gem and optionally adds trestle-auth and trestle-search.
If you wish to use Devise with trestle-auth, ensure that you have installed and configured Devise first and created a user model.
If not using Devise, the template will create a login [email protected] / admin.
If you wish to use Devise with trestle-auth, ensure that you have installed and configured Devise first and created a user model.
If not using Devise, the template will create a login [email protected] / admin.
Run this command in your Rails app directory in the terminal:
rails app:template LOCATION="https://railsbytes.com/script/zmnsyx"
Template Source
Review the code before running this template on your machine.
def do_bundle
# Custom bundle command ensures dependencies are correctly installed
Bundler.with_unbundled_env { run "bundle install" }
end
# Install trestle
gem "trestle"
do_bundle
run "rails generate trestle:install"
# Install trestle-auth
if yes?("Do you want to add authentication (with trestle-auth)? [y/n]")
gem "trestle-auth"
do_bundle
if yes?("Do you want to use Devise with trestle-auth? [y/n]")
model = ask("What is the name of your (existing) Devise user model?", default: "User")
run "rails generate trestle:auth:install #{model} --devise"
else
model = ask("What is the name of the admin user model you want to generate?", default: "Administrator")
run "rails generate trestle:auth:install #{model}"
run "rails db:migrate"
run "rails runner '#{model}.create(first_name: \"Admin\", last_name: \"User\", email: \"[email protected]\", password: \"admin\")'"
end
end
# Install trestle-search
if yes?("Do you want to add search (with trestle-search)? [y/n]")
gem "trestle-search"
do_bundle
end