Static Pages with High Voltage

Episode #12 by Teacher's Avatar David Kimura

Summary

Creating Static Pages within your Rails application is easy and configurable with High Voltage.
rails view 5:11

Resources

Summary

# Gemfile
    gem 'high_voltage'

# bash
    mkdir app/views/pages
    touch app/views/pages/about.html.erb
    touch app/views/pages/contact.html.erb

# config/initializers/high_voltage.rb
    HighVoltage.configure do |config|
      # Root path like /
      # config.home_page = 'about'

      # Set Root Routes like /about
      # config.route_drawer = HighVoltage::RouteDrawers::Root

      # Change the content path /pages/about to /site/about
      # config.content_path = 'site/'

      # Disable Routes
      # config.routes = false

      # Default Layout
      # config.layout = 'your_layout'

    end

# config/routes.rb
    get "/pages/*id" => 'pages#show', as: :page, format: false
    root to: 'pages#show', id: 'about'

# bash
    rails generate controller pages

# controllers/pages_controller.rb
    class PagesController < ApplicationController
      include HighVoltage::StaticPage

      before_filter :authenticate
      layout :layout_for_page

      private

      def layout_for_page
        case params[:id]
        when 'home'
          'home'
        else
          'application'
        end
      end
    end