Skip to content

rlogwood/rails_addons

Repository files navigation

Bite-size Addons for an existing Rails App Using Templates

NOTE:

Rails 7 requires redis for turbo-streams. For Ubuntu 20.04.4, Rails 7.0.2.2 and ruby 3.1.1p18 this was a manual install gem install redis

Usage

The add-ons are named to indicate their purpose. The documentation is a WIP. To get started and experiment try one of the scripts in bin.

Note, the utilities create Rails 7 apps. For newbies to Rails 7, to start the app, cd to the app directory and run bin/dev. Visit localhost:3000 in your browser.

1. Some add-ons require cloning the repo locally.

  1. Clone the repo locally
  2. Follow the steps in an example run, using your environment

2. Other add-ons can be run directly from github.

  • For example to update the tailwind configuration of a new rails 7 application with a basic setup:
    bin/rails app:template LOCATION=https://raw.githubusercontent.com/rlogwood/rails_addons/main/add_tailwind_scaffold/template.rb --trace

3. Some add-ons work well together

  • For example, to create a basic rails 7 tailwind app with devise, a navigation bar and blog use the provided script bin/create_rails_app.rb. This script will run several add-ons in the right order to create a basic app.

Recipies

Creating basic Rails 7, tailwind, devise app This script will run the following add-on templates in order to create Rails 7 TailwindCSS application with Devise authentication, a navigation bar and several pages (home, about, services), a blog and post model. The script will prompt for an email address and password and add an admin user that can create posts.
  • rails7_tailwind_config
  • add_tailwind_scaffold
  • add_devise
  • add_pages_devise_nav
  • add_cancancan
  • add_blog
  • add_error_pages

Create the app:

  • NOTE: Most of the individual addons can be run directly from the repo but to run the script that creates the app applying all the above addons , you must first clone the repo

    # clone the repo
    # run the ruby script
    % (repo_location)/bin/create_rails_app.rb
  • TODOs: WIP, improve layout and styling

How to run specific Add-ons

Active Storage Test (requires clone)

Basic ActiveStorage test with Digital Ocean spaces

This simple template distills down only the changes needed to make NEW Rails 6 app work with ActiveStorage using Digital Ocean spaces. Use this example as a simple reference application to see how ActiveStorage works.

An advanced use case is to run the template for an existing application. Do this on a new, clean working branch so that you can see all the files that are added and changed. The template will support the following use cases:

  • using asset pipeline for css and webpacker 5 or 6 for javascript
  • using webpacker 5 or 6 for both css and javascript
  • NOTE: Adding the template to existing applications has only been tested on webpacker 6 apps using webpacker for CSS
Example Run for Active Storage Test

cd ~/mystuff

app_name=(your app name here)

echo "creating a default rails app with postgresql"
rails new $app_name -d postgresql

echo "adding active storage"
cd $app_name

template="~/mystuff/rails_addons/active_storage_test/template.rb"

bin/rails app:template LOCATION=$template --trace

bin/rails db:create
bin/rails db:migrate

# note install s3cmd (if you use brew: brew install s3cmd)
# configure s3cmd with s3cmd --configure (https://docs.digitalocean.com/products/spaces/resources/s3cmd/)

s3cmd setcors lib/active_storage_config/digital_ocean/cors.xml s3://(my bucket) 
 
export S3_KEY=(my key)
export S3_SECRET=(my secret))

bin/rails s

About

Bite-size Add-ons for an existing Rails App Using Templates

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published