Skip to content

Commit ae80f43

Browse files
justin808claude
andcommitted
Add React on Rails Quick Start example application
This commit adds a complete example Rails application that demonstrates the React on Rails setup process following our 15-minute quick-start guide. ## What's included: ### Complete Working Example - Full Rails 7 + React 19 + Shakapacker 8.3 setup - HelloWorld React component with interactive features - Props passing from Rails controller to React component - Hot Module Replacement (HMR) ready for development - Server-side rendering capability (configurable) ### Generated Structure - Rails controller, views, and routes - React components with CSS modules - Webpack configuration for client and server bundles - Development scripts (bin/dev, bin/dev-static) - Comprehensive README with usage instructions ### Validation of Documentation - Proves the quick-start guide works exactly as documented - Demonstrates expected file structure after setup - Provides working reference for development and testing - Shows best practices for React on Rails integration ## Purpose: 1. **Documentation validation** - Ensures our quick-start guide is accurate 2. **Developer reference** - Shows complete working example 3. **Testing resource** - Provides baseline for development and CI 4. **Onboarding aid** - Helps new users understand the setup ## Quick test: ```bash cd spec/quick-start bundle install && npm install ./bin/dev # Visit http://localhost:3000/hello_world ``` This example serves as both documentation validation and a practical reference for developers getting started with React on Rails. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 15bd1aa commit ae80f43

File tree

118 files changed

+40492
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+40492
-1
lines changed

spec/quick-start

Lines changed: 0 additions & 1 deletion
This file was deleted.

spec/quick-start/.dockerignore

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.
2+
3+
# Ignore git directory.
4+
/.git/
5+
/.gitignore
6+
7+
# Ignore bundler config.
8+
/.bundle
9+
10+
# Ignore all environment files (except templates).
11+
/.env*
12+
!/.env*.erb
13+
14+
# Ignore all default key files.
15+
/config/master.key
16+
/config/credentials/*.key
17+
18+
# Ignore all logfiles and tempfiles.
19+
/log/*
20+
/tmp/*
21+
!/log/.keep
22+
!/tmp/.keep
23+
24+
# Ignore pidfiles, but keep the directory.
25+
/tmp/pids/*
26+
!/tmp/pids/.keep
27+
28+
# Ignore storage (uploaded files in development and any SQLite databases).
29+
/storage/*
30+
!/storage/.keep
31+
/tmp/storage/*
32+
!/tmp/storage/.keep
33+
34+
# Ignore assets.
35+
/node_modules/
36+
/app/assets/builds/*
37+
!/app/assets/builds/.keep
38+
/public/assets
39+
40+
# Ignore CI service files.
41+
/.github
42+
43+
# Ignore development files
44+
/.devcontainer
45+
46+
# Ignore Docker-related files
47+
/.dockerignore
48+
/Dockerfile*
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: bundler
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10
8+
- package-ecosystem: github-actions
9+
directory: "/"
10+
schedule:
11+
interval: daily
12+
open-pull-requests-limit: 10
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main ]
7+
8+
jobs:
9+
scan_ruby:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Ruby
17+
uses: ruby/setup-ruby@v1
18+
with:
19+
ruby-version: .ruby-version
20+
bundler-cache: true
21+
22+
- name: Scan for common Rails security vulnerabilities using static analysis
23+
run: bin/brakeman --no-pager
24+
25+
scan_js:
26+
runs-on: ubuntu-latest
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Ruby
33+
uses: ruby/setup-ruby@v1
34+
with:
35+
ruby-version: .ruby-version
36+
bundler-cache: true
37+
38+
- name: Scan for security vulnerabilities in JavaScript dependencies
39+
run: bin/importmap audit
40+
41+
lint:
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Checkout code
45+
uses: actions/checkout@v4
46+
47+
- name: Set up Ruby
48+
uses: ruby/setup-ruby@v1
49+
with:
50+
ruby-version: .ruby-version
51+
bundler-cache: true
52+
53+
- name: Lint code for consistent style
54+
run: bin/rubocop -f github
55+
56+
test:
57+
runs-on: ubuntu-latest
58+
59+
# services:
60+
# redis:
61+
# image: redis
62+
# ports:
63+
# - 6379:6379
64+
# options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
65+
steps:
66+
- name: Install packages
67+
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y google-chrome-stable curl libjemalloc2 libvips sqlite3
68+
69+
- name: Checkout code
70+
uses: actions/checkout@v4
71+
72+
- name: Set up Ruby
73+
uses: ruby/setup-ruby@v1
74+
with:
75+
ruby-version: .ruby-version
76+
bundler-cache: true
77+
78+
- name: Run tests
79+
env:
80+
RAILS_ENV: test
81+
# REDIS_URL: redis://localhost:6379/0
82+
run: bin/rails db:test:prepare test test:system
83+
84+
- name: Keep screenshots from failed system tests
85+
uses: actions/upload-artifact@v4
86+
if: failure()
87+
with:
88+
name: screenshots
89+
path: ${{ github.workspace }}/tmp/screenshots
90+
if-no-files-found: ignore

spec/quick-start/.rubocop.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Omakase Ruby styling for Rails
2+
inherit_gem: { rubocop-rails-omakase: rubocop.yml }
3+
4+
# Overwrite or add rules to create your own house style
5+
#
6+
# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
7+
# Layout/SpaceInsideArrayLiteralBrackets:
8+
# Enabled: false

spec/quick-start/Dockerfile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# syntax = docker/dockerfile:1
2+
3+
# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
4+
# docker build -t my-app .
5+
# docker run -d -p 80:80 -p 443:443 --name my-app -e RAILS_MASTER_KEY=<value from config/master.key> my-app
6+
7+
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
8+
ARG RUBY_VERSION=3.3.7
9+
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
10+
11+
# Rails app lives here
12+
WORKDIR /rails
13+
14+
# Install base packages
15+
RUN apt-get update -qq && \
16+
apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 && \
17+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
18+
19+
# Set production environment
20+
ENV RAILS_ENV="production" \
21+
BUNDLE_DEPLOYMENT="1" \
22+
BUNDLE_PATH="/usr/local/bundle" \
23+
BUNDLE_WITHOUT="development"
24+
25+
# Throw-away build stage to reduce size of final image
26+
FROM base AS build
27+
28+
# Install packages needed to build gems
29+
RUN apt-get update -qq && \
30+
apt-get install --no-install-recommends -y build-essential git pkg-config && \
31+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
32+
33+
# Install application gems
34+
COPY Gemfile Gemfile.lock ./
35+
RUN bundle install && \
36+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
37+
bundle exec bootsnap precompile --gemfile
38+
39+
# Copy application code
40+
COPY . .
41+
42+
# Precompile bootsnap code for faster boot times
43+
RUN bundle exec bootsnap precompile app/ lib/
44+
45+
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
46+
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
47+
48+
49+
50+
51+
# Final stage for app image
52+
FROM base
53+
54+
# Copy built artifacts: gems, application
55+
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
56+
COPY --from=build /rails /rails
57+
58+
# Run and own only the runtime files as a non-root user for security
59+
RUN groupadd --system --gid 1000 rails && \
60+
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
61+
chown -R rails:rails db log storage tmp
62+
USER 1000:1000
63+
64+
# Entrypoint prepares the database.
65+
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
66+
67+
# Start the server by default, this can be overwritten at runtime
68+
EXPOSE 3000
69+
CMD ["./bin/rails", "server"]

spec/quick-start/Gemfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
source "https://rubygems.org"
2+
3+
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
4+
gem "rails", "~> 7.2.2", ">= 7.2.2.1"
5+
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
6+
gem "sprockets-rails"
7+
# Use sqlite3 as the database for Active Record
8+
gem "sqlite3", ">= 1.4"
9+
# Use the Puma web server [https://github.com/puma/puma]
10+
gem "puma", ">= 5.0"
11+
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
12+
gem "jbuilder"
13+
# Use Redis adapter to run Action Cable in production
14+
# gem "redis", ">= 4.0.1"
15+
16+
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
17+
# gem "kredis"
18+
19+
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
20+
# gem "bcrypt", "~> 3.1.7"
21+
22+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
23+
gem "tzinfo-data", platforms: %i[ windows jruby ]
24+
25+
# Reduces boot times through caching; required in config/boot.rb
26+
gem "bootsnap", require: false
27+
28+
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
29+
# gem "image_processing", "~> 1.2"
30+
31+
group :development, :test do
32+
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
33+
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
34+
35+
# Static analysis for security vulnerabilities [https://brakemanscanner.org/]
36+
gem "brakeman", require: false
37+
38+
# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
39+
gem "rubocop-rails-omakase", require: false
40+
end
41+
42+
group :development do
43+
# Use console on exceptions pages [https://github.com/rails/web-console]
44+
gem "web-console"
45+
end
46+
47+
group :test do
48+
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
49+
gem "capybara"
50+
gem "selenium-webdriver"
51+
end
52+
53+
gem "shakapacker", "= 8.3"
54+
gem "react_on_rails", path: "../.."

0 commit comments

Comments
 (0)