Administrate

Adds and performs basic config for Administrate
Icons/chart bar
Used 12 times
Created by
D Drew Bragg

Usage

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/zNPs0l"
Template Source

Review the code before running this template on your machine.

gem 'administrate'

run 'bundle install'

# installation fails unless we disable spring after bundling
run 'DISABLE_SPRING=true rails g administrate:install'

helper = <<-RUBY
# Expose our application's helpers to Administrate
config.to_prepare do
  Administrate::ApplicationController.helper #{Rails.application.class.module_parent_name.camelize}::Application.helpers
end
RUBY

environment helper + "\n"

append_to_file "app/assets/config/manifest.js", "//= link administrate/application.css\n//= link administrate/application.js"

gsub_file 'app/controllers/admin/application_controller.rb', /# TODO Add authentication logic here\./, "redirect_to '/', alert: 'Not authorized.' unless user_signed_in? && current_user.admin?"
Comments

Sign up or Login to leave a comment.

© 2022 GoRails, LLC