Class: Webring::Generators::NavigationControllerGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Shared::RouteInjector
Defined in:
lib/generators/webring/navigation_controller/navigation_controller_generator.rb

Overview

Note:

This generator should be run after installing the Webring engine and generating the Member model with webring:member

This generator creates both the controller file and adds the required routes

Examples:

The generated controller provides three main navigation endpoints:

# GET /webring/next     - Navigate to the next site in the webring
# GET /webring/previous - Navigate to the previous site in the webring
# GET /webring/random   - Navigate to a random site in the webring

Instance Method Summary collapse

Instance Method Details

#create_controller_fileObject

Creates the NavigationController file based on the template



25
26
27
# File 'lib/generators/webring/navigation_controller/navigation_controller_generator.rb', line 25

def create_controller_file
  template 'navigation_controller.rb', 'app/controllers/webring/navigation_controller.rb'
end

#create_navigation_routesObject

Adds navigation routes to the application’s routes.rb file These routes are used to navigate between webring members



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/webring/navigation_controller/navigation_controller_generator.rb', line 31

def create_navigation_routes
  route_content = <<~ROUTE
    # Webring navigation routes
    namespace :webring do
      root to: 'navigation#random'

      get 'next', to: 'navigation#next'
      get 'previous', to: 'navigation#previous'
      get 'random', to: 'navigation#random'
    end
  ROUTE

  inject_webring_routes(route_content)
end