Skip to content

Instantly share code, notes, and snippets.

@rutvij-pandya
Last active May 1, 2018 11:39
Show Gist options
  • Save rutvij-pandya/4571afd313d885e8d63a66aad97174eb to your computer and use it in GitHub Desktop.
Save rutvij-pandya/4571afd313d885e8d63a66aad97174eb to your computer and use it in GitHub Desktop.
Steps to integrate pgHero with Rails
## Gemfile
gem 'pghero'
# pg_query is used by pghero to provide suggestions to add indexes
gem 'pg_query', '>= 0.9.0'
# bundle install
## Add a route to access the pgHero Dashboard
# You can secure its access with Devise user authentication
# Here we're giving access to only the users with super_admin role
## config/routes/rb
authenticate :user, -> (user) { user.has_role?(:super_admin) } do
mount PgHero::Engine, at: "pgdashboard"
end
## Alternatively,
# you can also secure the Dashboard with basic HTTP authentication
## config/routes/rb
mount PgHero::Engine, at: "pgdashboard"
# Add environment variables mentioned as per below
ENV["PGHERO_USERNAME"] = "<username>"
ENV["PGHERO_PASSWORD"] = "<password>"
## You may link to link it with you admin portal
# some-menu.html.erb
<%= link_to "Database Analyzer", pg_hero_path, target: :blank %>
## Restart your rails application and try to access "/pgdashboard" path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment