### Generate React on Rails Install Files Source: https://github.com/shakacode/react_on_rails/blob/master/docs/getting-started/installation-into-an-existing-rails-app.md Execute the React on Rails install generator to create initial configuration files and a 'Hello World' example. Use `--help` for a list of available options. ```bash rails generate react_on_rails:install rails generate react_on_rails:install --help ``` -------------------------------- ### Install React on Rails Gem and Installer Source: https://github.com/shakacode/react_on_rails/blob/master/docs/getting-started/quick-start.md Installs the React on Rails gem using Bundler and then runs the generator to set up the necessary files and configurations for integrating React components into a Rails application. It also notes an option to use Rspack for faster builds. ```bash bundle add react_on_rails --strict git add . && git commit -m "Add react_on_rails gem" bin/rails generate react_on_rails:install # Optional: Use Rspack for ~20x faster builds # bin/rails generate react_on_rails:install --rspack ``` -------------------------------- ### Start sample app with static assets Source: https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/README.md Starts the sample app with static loading of Rails assets using Foreman. Requires Foreman to be installed. ```shell foreman start -f Procfile.dev-static-assets ``` -------------------------------- ### Start sample app with hot reloading Source: https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/README.md Starts the sample app with hot reloading of Rails assets using Foreman. Requires Foreman to be installed. ```shell foreman start -f Procfile.dev ``` -------------------------------- ### Install React on Rails in New Rails App Source: https://github.com/shakacode/react_on_rails/blob/master/AI_AGENT_INSTRUCTIONS.md This sequence of commands sets up a new Rails application with React on Rails. It includes creating the Rails app, adding the gem, running the generator, and starting the development server. Assumes PostgreSQL database. ```bash # Create new Rails app rails new myapp --skip-javascript --database=postgresql cd myapp # Use latest version bundle add react_on_rails --strict bin/rails generate react_on_rails:install # Accept change to bin/dev # Start development servers bin/dev ``` -------------------------------- ### Bash Script for React on Rails Monorepo Setup Source: https://github.com/shakacode/react_on_rails/blob/master/docs/MONOREPO_MERGER_PLAN.md A bash script demonstrating the setup process for the React on Rails monorepo. It includes cloning the repository, installing Ruby and NPM dependencies, building packages, running tests, and starting the development server. This is crucial for developers new to the project. ```bash # Clone the monorepo git clone https://github.com/shakacode/react_on_rails.git cd react_on_rails # Install dependencies bundle install # Ruby gems yarn install # NPM packages (workspace) # Build all packages yarn build # NPM packages rake build:gems # Ruby gems # Run tests yarn test # NPM package tests bundle exec rspec spec/ruby # Ruby tests # Development commands yarn workspace react-on-rails build # Build core package yarn workspace react-on-rails-pro test # Test pro package cd packages/react-on-rails && yarn dev # Development server ``` -------------------------------- ### Troubleshoot React on Rails Setup Source: https://github.com/shakacode/react_on_rails/blob/master/AI_AGENT_INSTRUCTIONS.md A collection of commands and tips for troubleshooting React on Rails setup issues. Includes starting and stopping development servers, and running a diagnostic tool. ```bash # Always run `bin/dev` to test setup, and check browser console for any JavaScript errors # `bin/dev kill` stops other conflicting processes # `bin/rake react_on_rails:doctor` for helpful information ``` -------------------------------- ### Install Shakapacker with React Source: https://github.com/shakacode/react_on_rails/blob/master/docs/getting-started/installation-into-an-existing-rails-app.md Run the Shakapacker install generator to set up Shakapacker with React support in your Rails application. This command prepares your project for frontend asset management. ```bash rails shakapacker:install ``` -------------------------------- ### Install Shakapacker and React on Rails using Bundler Source: https://github.com/shakacode/react_on_rails/blob/master/docs/getting-started/installation-into-an-existing-rails-app.md Use the `bundle add` command to install Shakapacker and React on Rails, specifying exact versions. This method is an alternative to directly editing the Gemfile. ```bash bundle add shakapacker --version=7.0.1 --strict bundle add react_on_rails --version=13.3.1 --strict ``` -------------------------------- ### Create assets for tests Source: https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/README.md Starts the process to create assets for tests using Foreman. Requires Foreman to be installed. ```shell foreman start -f Procfile.spec ``` -------------------------------- ### Manually Install React on Rails via Yarn Source: https://github.com/shakacode/react_on_rails/blob/master/docs/getting-started/installation-into-an-existing-rails-app.md Manually install the `react-on-rails` npm package using Yarn. The `--exact` flag ensures that the version in `package.json` is precise, avoiding version conflicts. ```bash yarn add react-on-rails --exact ``` -------------------------------- ### Automate License Updates Across CI Systems Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/CI_SETUP.md This bash script example illustrates how to automate the process of updating the React on Rails Pro license token across multiple CI systems. This is useful for centralized license management, especially for teams. ```bash # Example: Update license across multiple CI systems ./update-ci-license.sh "new-license-token" ``` -------------------------------- ### Start Development Server with Foreman Source: https://github.com/shakacode/react_on_rails/blob/master/CODING_AGENTS.md Command to start the dummy application for development using Foreman. This command assumes the dummy application is in the 'spec/dummy' directory and starts the necessary processes, including webpack. ```bash # Development cd spec/dummy && foreman start # Start dummy app with webpack ``` -------------------------------- ### Travis CI Config with License Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/CI_SETUP.md This Travis CI configuration specifies the Ruby and Node.js versions to use for the build. It enables caching for Bundler and Yarn. The `before_install` script ensures the correct Node.js version is installed, and then `install` commands fetch project dependencies. The `script` command executes the RSpec tests, with the license implicitly available via environment variables configured in Travis CI. ```yaml # .travis.yml language: ruby rvm: - 3.3 node_js: - 18 cache: bundler: true yarn: true before_install: - nvm install 18 - node --version - yarn --version install: - bundle install - yarn install script: - bundle exec rspec # License is automatically available from environment variables ``` -------------------------------- ### Essential React on Rails CLI Commands Source: https://github.com/shakacode/react_on_rails/blob/master/docs/getting-started/quick-start.md A collection of essential bash commands for managing a React on Rails project. These include starting development servers, generating boilerplate code for React on Rails and new components, and building the project for production. ```bash # Start development servers ./bin/dev # Generate React on Rails files bin/rails generate react_on_rails:install # Create a new component bin/rails generate react_on_rails:component MyComponent # Build for production yarn run build ``` -------------------------------- ### Installing react_on_rails_pro Gem via Command Line Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/docs/installation.md This Bash command installs the react_on_rails_pro gem directly from the private GitHub Packages source. It requires a version specifier and relies on the source URL being configured. Inputs include version and source; the command executes gem installation. Limitations include potential need for separate bundler configuration for private repos. ```bash gem install react_on_rails_pro --version "" --source "https://rubygems.pkg.github.com/shakacode-tools" ``` -------------------------------- ### Install Node Renderer from GitHub Branch Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/docs/installation.md This command installs the Node renderer executable globally using yarn, specifying a GitHub repository and a branch. It requires a GitHub token for authentication to access private repositories. ```bash yarn global add https://:x-oauth-basic@github.com/shakacode/react_on_rails_pro.git#master ``` -------------------------------- ### Setting Up and Migrating PostgreSQL Database (Bash) Source: https://github.com/shakacode/react_on_rails/blob/master/docs/deployment/heroku-deployment.md Initializes and applies migrations for the PostgreSQL database locally after configuration. Purpose: Prepare schema for development and testing. Dependencies: Local Postgres installed; Input: Updated database.yml; Output: Database created and migrated; Limitation: Run only after yml setup. ```bash rake db:setup rake db:migrate ``` -------------------------------- ### GitHub Actions CI/CD Workflow with License Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/CI_SETUP.md This YAML configuration sets up a GitHub Actions workflow to run tests. It checks out the code, sets up Ruby and Node.js environments, installs dependencies, and runs RSpec tests. Crucially, it injects the `REACT_ON_RAILS_PRO_LICENSE` from GitHub secrets into the environment variables for the job. ```yaml # .github/workflows/test.yml name: Tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest env: REACT_ON_RAILS_PRO_LICENSE: ${{ secrets.REACT_ON_RAILS_PRO_LICENSE }} steps: - uses: actions/checkout@v3 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: 3.3 bundler-cache: true - name: Set up Node uses: actions/setup-node@v3 with: node-version: '18' cache: 'yarn' - name: Install dependencies run: | bundle install yarn install - name: Run tests run: bundle exec rspec ``` -------------------------------- ### Set up yalc for React on Rails Source: https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/README.md Publishes the react_on_rails package using yalc and links it in the dummy project. Requires yalc and bundle to be installed. ```shell cd react_on_rails bundle install yalc publish cd spec/dummy bundle install yalc link react-on-rails ``` -------------------------------- ### Install Yarn dependencies for React on Rails Source: https://github.com/shakacode/react_on_rails/blob/master/spec/dummy/README.md Installs Yarn dependencies for the dummy project and builds Rescript assets. Requires Yarn to be installed. ```shell cd react_on_rails yarn run dummy:install cd spec/dummy yarn build:rescript ``` -------------------------------- ### Define Node Renderer Dependencies and Scripts in package.json Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/docs/installation.md This JSON configuration defines the private package.json for the Node renderer subdirectory. It specifies the dependency for the React on Rails Pro Node renderer package and includes a script to start the renderer. ```json { "private": true, "dependencies": { "@shakacode-tools/react-on-rails-pro-node-renderer": "" }, "scripts": { "node-renderer": "echo 'Starting React on Rails Pro Node Renderer.' && node ./react-on-rails-pro-node-renderer.js" } } ``` -------------------------------- ### Start Local Verdaccio Registry and Publish Source: https://github.com/shakacode/react_on_rails/blob/master/docs/contributor-info/releasing.md Installs and starts a local Verdaccio registry for testing NPM package publishing. It then runs a rake release task to publish NPM packages to this local registry and skips RubyGem publishing. ```bash npm install -g verdaccio verdaccio ``` ```bash rake release[patch,false,verdaccio] ``` -------------------------------- ### GitLab CI/CD Pipeline with License Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/CI_SETUP.md This GitLab CI/CD configuration defines a pipeline for testing. It uses a Ruby image, sets up necessary environment variables, installs dependencies including Node.js and Yarn, and then executes RSpec tests. The `REACT_ON_RAILS_PRO_LICENSE` is expected to be configured directly in GitLab's CI/CD variables. ```yaml # .gitlab-ci.yml image: ruby:3.3 variables: RAILS_ENV: test NODE_ENV: test before_script: - gem install bundler - bundle install --jobs $(nproc) - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - - echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list - apt-get update && apt-get install -y nodejs yarn - yarn install test: script: - bundle exec rspec # License is automatically available from CI/CD variables ``` -------------------------------- ### Execute Common React on Rails Commands Source: https://github.com/shakacode/react_on_rails/blob/master/docs/contributor-info/coding-agents-guide.md Essential bash commands for React on Rails development. Includes generating JavaScript routes, running install generators, building assets, and starting development servers. These commands require both Ruby on Rails and Node.js environments and are fundamental for daily development workflows. ```bash # Generate JavaScript routes (critical step) bundle exec rails js:export # Install generator (review before applying) rails generate react_on_rails:install # Build assets npm run build # Start development server bin/dev ``` -------------------------------- ### Adding react_on_rails_pro Gem with Specific Branch to Gemfile Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/docs/installation.md This Ruby Gemfile entry installs the react_on_rails_pro gem from a specific branch on GitHub. It uses Git authentication with a token for private access. Dependencies include a GitHub token and version/tag. Recommended to use environment variables for security. Note: This is for using pre-release or branch-specific versions. ```ruby gem "react_on_rails_pro", version: "", git: "https://[your-github-token]:x-oauth-basic@github.com/shakacode/react_on_rails_pro.git", tag: "" ``` -------------------------------- ### Install React on Rails in New Rails App Source: https://github.com/shakacode/react_on_rails/blob/master/docs/contributor-info/coding-agents-guide.md Complete installation workflow for React on Rails in new Rails applications. Installs Shakapacker, adds the React on Rails gem, runs the generator, installs dependencies, and validates the build. Requires Rails CLI, Bundler, and npm with version constraints for compatibility. ```bash # 1. Create Rails app rails new PROJECT_NAME --skip-javascript cd PROJECT_NAME # 2. Install Shakapacker bundle add shakapacker --strict rails shakapacker:install # 3. Install React on Rails bundle add react_on_rails --version=16.0.0 --strict # 4. Run generator rails generate react_on_rails:install # 5. Install JavaScript dependencies npm install # 6. Generate routes (if using js-routes) bundle exec rails js:export # 7. Test build npm run build ``` -------------------------------- ### Install vm-renderer Node package globally Source: https://github.com/shakacode/react_on_rails/wiki/Installation Installs the vm-renderer executable globally using yarn from a private GitHub repository. This is required for the standalone node renderer functionality. Requires GitHub OAuth token authentication. ```bash yarn global add https://:x-oauth-basic@github.com/shakacode/react_on_rails_pro.git\#master ``` -------------------------------- ### Add react_on_rails_pro gem to Gemfile Source: https://github.com/shakacode/react_on_rails/wiki/Installation Installs the react_on_rails_pro gem from a private GitHub repository using OAuth authentication. Requires a valid GitHub OAuth token for access. The gem enables enhanced React on Rails functionality. ```ruby gem "react_on_rails_pro", git: "https://[your-github-token]:x-oauth-basic@github.com/shakacode/react_on_rails-pro.git", tag: "1.1.0" ``` -------------------------------- ### Check React on Rails Gem Versions Source: https://github.com/shakacode/react_on_rails/blob/master/AI_AGENT_INSTRUCTIONS.md This command retrieves the latest available versions of the react_on_rails gem from the remote repository. It is recommended to run this before installation to ensure you are using the most up-to-date version. ```bash # Get latest available versions (recommended approach) gem search react_on_rails --remote ``` -------------------------------- ### Add React on Rails Gems to Gemfile Source: https://github.com/shakacode/react_on_rails/blob/master/docs/getting-started/installation-into-an-existing-rails-app.md Add the Shakapacker and React on Rails gems to your project's Gemfile. It is recommended to pin the versions to ensure consistency between your Gemfile and package.json. ```ruby gem "shakapacker", "7.0.1" # Use the latest and the exact version gem "react_on_rails", "13.3.1" # Use the latest and the exact version ``` -------------------------------- ### Run vm-renderer Command Line Source: https://github.com/shakacode/react_on_rails/wiki/Node-React-Render-Docs This command starts the vm-renderer server using environment variables for configuration. You can optionally specify the port using the -p argument. Ensure RENDERER_BUNDLE_PATH is set to your bundle's location. ```sh RENDERER_BUNDLE_PATH=/tmp/bundle-path vm-renderer RENDERER_BUNDLE_PATH=/tmp/bundle-path vm-renderer -p 3800 ``` -------------------------------- ### Install and Run Tests in React on Rails Source: https://github.com/shakacode/react_on_rails/blob/master/CODING_AGENTS.md Commands to install project dependencies using Bundler and Yarn, and to run RSpec tests for the entire project or just the dummy application. Ensures the project is set up correctly for development and testing. ```bash # Install dependencies bundle && yarn # Run tests bundle exec rspec # All tests (from project root) cd spec/dummy && bundle exec rspec # Dummy app tests only ``` -------------------------------- ### Configure npm for GitHub Packages Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/docs/installation.md This configuration snippet sets up npm to authenticate with GitHub Packages, which is necessary for installing private packages. It ensures that authentication tokens are used when accessing the specified registry. ```bash //npm.pkg.github.com/:_authToken= ``` -------------------------------- ### Initialize Node.js Application and Add React on Rails Pro Source: https://github.com/shakacode/react_on_rails/wiki/Node-React-Render-Docs These commands initialize a new Node.js project and install the react-on-rails-pro-vm-renderer package using Yarn. This is the first step in setting up a custom JavaScript configuration file for the VM Renderer. ```sh mkdir renderer-app cd renderer-app yarn init yarn add https://[your-github-token]:x-oauth-basic@github.com/shakacode/react_on_rails_pro.git#master ``` -------------------------------- ### Setup React on Rails Pro License in Bitbucket Pipelines Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/CI_SETUP.md This snippet demonstrates integrating React on Rails Pro license in Bitbucket Pipelines using repository variables. The license is automatically available as an environment variable during pipeline execution. Dependencies include a valid license token added as a secured repository variable. No explicit loading is required in the pipeline script. ```yaml # bitbucket-pipelines.yml image: ruby:3.3 definitions: caches: bundler: vendor/bundle yarn: node_modules pipelines: default: - step: name: Test caches: - bundler - yarn script: - apt-get update && apt-get install -y nodejs npm - npm install -g yarn - bundle install --path vendor/bundle - yarn install - bundle exec rspec # License is automatically available from repository variables ``` -------------------------------- ### Configure React on Rails Pro VM Renderer with JavaScript Source: https://github.com/shakacode/react_on_rails/wiki/Node-React-Render-Docs This JavaScript code configures the VM Renderer server. It imports the necessary module and sets the bundlePath. This file is then executed with Node.js to start the renderer. ```javascript import path from 'path'; import reactOnRailsProVmRenderer from 'react-on-rails-pro-vm-renderer'; const config = { bundlePath: path.resolve(__dirname, '../tmp/bundles'), }; reactOnRailsProVmRenderer(config); ``` -------------------------------- ### Configure Bundler for Private GitHub Packages Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/docs/installation.md This command configures Bundler to use a private GitHub registry for packages. It specifies the registry URL and provides authentication credentials (username and token) to allow Bundler to access private gems. ```bash bundle config https://rubygems.pkg.github.com/OWNER USERNAME:TOKEN ``` -------------------------------- ### Commit Initial Setup Changes with Git Source: https://github.com/shakacode/react_on_rails/blob/master/docs/getting-started/tutorial.md This commits all modifications from the installation steps to version control, preventing errors in subsequent generators. Requires Git initialized in the project; includes all staged changes from gem additions and generator runs. Alternative: use --ignore-warnings flag on next steps if not committing. ```bash git commit -am "Initial commit" ``` -------------------------------- ### Run React on Rails Development Server (Bash) Source: https://github.com/shakacode/react_on_rails/blob/master/docs/getting-started/tutorial.md Starts the React on Rails development server. Supports Hot Module Replacement (HMR) with './bin/dev' or static bundle creation with './bin/dev static'. ```bash ./bin/dev # For HMR ``` ```bash ./bin/dev static # Without HMR, statically creating the bundles ``` -------------------------------- ### Start development server with bin/dev Source: https://github.com/shakacode/react_on_rails/blob/master/docs/building-features/process-managers.md Executes the bin/dev script which automatically uses Overmind or Foreman to start the development servers. Falls back to installation instructions if neither is installed. ```bash ./bin/dev ``` -------------------------------- ### Run Webpack Dev Server in Bash Source: https://github.com/shakacode/react_on_rails/blob/master/docs/deployment/troubleshooting.md Starts webpack-dev-server via Procfile.dev for hot reloading and faster development builds. Depends on bin/dev script setup. Input is terminal command; output is running dev server. Limitation: Requires Procfile.dev configuration. ```bash ./bin/dev # Uses Procfile.dev with webpack-dev-server ``` -------------------------------- ### Create New Rails App with Bash Source: https://github.com/shakacode/react_on_rails/blob/master/docs/getting-started/tutorial.md This command creates a new Ruby on Rails application skipping default JavaScript setup to prepare for React integration. It targets Rails 7.0+ but includes a note for Rails 6.x compatibility. Requires Rails installed; outputs a new directory structure for the app. ```bash # For Rails 6.x rails new test-react-on-rails --skip-javascript # For Rails 7.x rails new test-react-on-rails --skip-javascript cd test-react-on-rails ``` -------------------------------- ### Testing Generator: No Shakapacker Installed Source: https://github.com/shakacode/react_on_rails/blob/master/CONTRIBUTING.md This section details the process of testing the React on Rails generator in a fresh Rails application where Shakapacker is not initially installed. It ensures the generator installs Shakapacker automatically and verifies the setup. ```bash # Reset to clean baseline before each test git clean -fd && git reset --hard generator_testing_base && git clean -fd # Ensure no Shakapacker in Gemfile (remove if present) # Edit Gemfile to update gem path: gem 'react_on_rails', path: '../path/to/main/repo' bundle install # Run generator - should install Shakapacker automatically ./bin/rails generate react_on_rails:install # Verify Shakapacker was added to Gemfile and installed correctly ``` -------------------------------- ### Post-Deployment Production Site Verification Source: https://github.com/shakacode/react_on_rails/blob/master/docs/planning/docs-improvement/04-ia-redesign-plan.md Opens the live documentation site in the browser for manual inspection after deployment. No specific dependencies beyond a web browser. Checks for correct rendering, redirects, and indexing; follow up with Google Search Console for SEO verification after a few days. ```bash open https://www.shakacode.com/react-on-rails/docs/ ``` -------------------------------- ### Create React on Rails Pro License Key File Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/LICENSE_SETUP.md Alternatively, install the React on Rails Pro license by creating a `config/react_on_rails_pro_license.key` file in your Rails application's root directory. It's crucial to add this file to your `.gitignore` to prevent accidental commits of your license key. ```bash echo "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..." > config/react_on_rails_pro_license.key # Add to .gitignore echo "config/react_on_rails_pro_license.key" >> .gitignore ``` -------------------------------- ### Install Shakapacker via Rails Generator Source: https://github.com/shakacode/react_on_rails/blob/master/docs/getting-started/tutorial.md This runs the Shakapacker installer to set up Webpacker-like functionality for asset compilation in Rails. Depends on the gems being added previously; generates configuration files and may require committing changes afterward to proceed. Outputs updated Rails structure for JavaScript bundling. ```bash bundle exec rails shakapacker:install ``` -------------------------------- ### RuboCop: Trailing Whitespace Fix Example Source: https://github.com/shakacode/react_on_rails/blob/master/CODING_AGENTS.md Demonstrates a common RuboCop violation for trailing whitespace and its correction. The 'Bad' example shows code with unnecessary spaces after a line, while the 'Good' example shows the cleaned-up version. ```ruby # Bad let(:value) { "test" } # Good let(:value) { "test" } ``` -------------------------------- ### Install ApacheBench (ab) - Linux Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/docs/profiling-server-side-rendering-code.md This snippet shows how to install ApacheBench on a Linux system to simulate high traffic to your application. It depends on the `apt-get` package manager. The output is a series of HTTP requests to a specified endpoint. ```bash sudo apt-get install apache2-utils ``` -------------------------------- ### CircleCI Config with License Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/CI_SETUP.md This CircleCI configuration defines a job named 'test' that uses a Docker image with Ruby and Node.js. It includes steps for checking out code, restoring and saving caches for gems and Yarn, installing dependencies, and running RSpec tests. The license is automatically picked up from environment variables set in CircleCI project settings. ```yaml # .circleci/config.yml version: 2.1 jobs: test: docker: - image: cimg/ruby:3.3-node steps: - checkout - restore_cache: keys: - gem-cache-{{ checksum "Gemfile.lock" }} - yarn-cache-{{ checksum "yarn.lock" }} - run: name: Install dependencies command: | bundle install --path vendor/bundle yarn install - save_cache: key: gem-cache-{{ checksum "Gemfile.lock" }} paths: - vendor/bundle - save_cache: key: yarn-cache-{{ checksum "yarn.lock" }} paths: - node_modules - run: name: Run tests command: bundle exec rspec # License is automatically available from environment variables workflows: version: 2 test: jobs: - test ``` -------------------------------- ### Install React on Rails Generator (Bash) Source: https://github.com/shakacode/react_on_rails/blob/master/docs/getting-started/tutorial.md Installs the React on Rails gem using the Rails generator. It prompts for confirmation on file changes and offers an option to include Redux integration. ```bash rails generate react_on_rails:install ``` ```bash rails generate react_on_rails:install --redux ``` -------------------------------- ### Install React on Rails Generator (Bash) Source: https://context7.com/shakacode/react_on_rails/llms.txt Installs the React on Rails gem and generator, configuring Shakapacker or Rspack for asset bundling and setting up example components. Supports TypeScript and Redux integrations. ```bash # Add to Gemfile gem 'react_on_rails', '~> 16.1' # Install gem bundle install # Run generator (installs Shakapacker, configures webpack, creates example components) rails generate react_on_rails:install # With TypeScript rails generate react_on_rails:install --typescript # With Redux rails generate react_on_rails:install --redux # With Rspack (20x faster builds) rails generate react_on_rails:install --rspack # Start development servers bin/dev ``` -------------------------------- ### Install Mini Racer Gem for JS Runtime in Bash Source: https://github.com/shakacode/react_on_rails/blob/master/docs/deployment/troubleshooting.md Adds mini_racer gem to Gemfile for JavaScript execution on server during SSR. Purpose is to enable Node.js-like environment in Ruby. Input is Gemfile; output is installed gem. Limitation: Only needed if missing; run bundle install after adding. ```bash # Add to Gemfile if missing gem 'mini_racer' ``` -------------------------------- ### Add Shakapacker and React on Rails Gems with Bundler Source: https://github.com/shakacode/react_on_rails/blob/master/docs/getting-started/tutorial.md These commands add the latest stable versions of the react_on_rails and shakapacker gems to the Gemfile using strict version pinning to avoid compatibility issues. Requires Bundler installed and a valid Gemfile; updates dependencies for React integration in Rails. Use exact versions without caret or tilde for stability. ```bash bundle add react_on_rails --strict bundle add shakapacker --strict ``` -------------------------------- ### Build NPM Package and Run Dummy App Specs Source: https://github.com/shakacode/react_on_rails/blob/master/CONTRIBUTING.md Installs NPM dependencies, builds the NPM package for react-on-rails, and then builds the Webpack files for the dummy app and runs its tests. Optionally sets the Capybara driver. ```shell # Optionally change default capybara driver export DRIVER=selenium_firefox cd react_on_rails/ yarn run dummy:spec ``` -------------------------------- ### Install React on Rails in Existing Rails App Source: https://github.com/shakacode/react_on_rails/blob/master/docs/contributor-info/coding-agents-guide.md Workflow for integrating React on Rails into existing Rails applications. Includes prerequisite verification, dry-run generator execution for change review, dependency installation, route generation, and build testing. Assumes Shakapacker is present or will be installed separately. ```bash # 1. Check prerequisites ls Gemfile | grep -q shakapacker || echo "⚠️ Shakapacker required" # 2. Add React on Rails bundle add react_on_rails --version=16.0.0 --strict # 3. Run generator (REVIEW CHANGES) rails generate react_on_rails:install --dry-run # If acceptable: rails generate react_on_rails:install # 4. Install dependencies bundle install npm install # 5. Generate routes (if using js-routes gem) bundle exec rails js:export # 6. Test npm run build ``` -------------------------------- ### Add React on Rails to Existing Rails App Source: https://github.com/shakacode/react_on_rails/blob/master/AI_AGENT_INSTRUCTIONS.md These commands integrate React on Rails into an existing Rails application. It involves navigating to the app directory, adding the gem, running the generator, and restarting the development server. ```bash cd /path/to/existing/app # Use latest version bundle add react_on_rails --strict bin/rails generate react_on_rails:install # Accept change to bin/dev # Start development servers bin/dev # Navigate to existing Rails app root # Start development bin/dev ``` -------------------------------- ### Install SWC Dependencies with Yarn Source: https://github.com/shakacode/react_on_rails/blob/master/docs/swc-migration.md Install the necessary SWC packages as dev dependencies to enable SWC transpilation in Shakapacker projects. Requires Yarn or npm and Shakapacker 9.0+. This step adds @swc/core for compilation and swc-loader for webpack integration, with no specific inputs or outputs beyond package installation. ```bash yarn add -D @swc/core swc-loader ``` -------------------------------- ### Check React On Rails Pro License Configuration File Source: https://github.com/shakacode/react_on_rails/blob/master/react_on_rails_pro/LICENSE_SETUP.md This command verifies the existence of the React on Rails Pro license key configuration file. Missing or inaccessible files can lead to application startup failures. ```shell ls config/react_on_rails_pro_license.key ``` -------------------------------- ### Commit changes and run React on Rails install generator Source: https://github.com/shakacode/react_on_rails/blob/master/docs/deployment/troubleshooting.md Ensures the git repository is clean before running the React on Rails installer. This prevents the generator from failing due to uncommitted changes. Run the commands in the project root. ```bash git add .\ngit commit -m \"Add react_on_rails gem\"\nbin/rails generate react_on_rails:install ``` -------------------------------- ### RSpec Test Structure Example Source: https://github.com/shakacode/react_on_rails/blob/master/CODING_AGENTS.md Provides a standard structure for RSpec tests, including `describe`, `context`, `let`, `before` blocks, and `it` examples. This structure helps organize tests for features and specific conditions. ```ruby describe "FeatureName" do context "when condition A" do let(:setup) { create_test_condition } before do # Setup code end it "does expected behavior" do # Arrange, Act, Assert end end end ``` -------------------------------- ### Run Development Servers Source: https://github.com/shakacode/react_on_rails/blob/master/CONTRIBUTING.md Starts the React on Rails development server with different configurations. 'bin/dev' enables Hot Module Replacement (HMR), 'bin/dev static' shows fewer warnings, and 'bin/dev prod' provides a production-like environment with minimal warnings. Resource preload warnings in development modes are expected. ```bash bin/dev bin/dev static bin/dev prod ``` -------------------------------- ### Install updates for React on Rails (bundle and npm) Source: https://github.com/shakacode/react_on_rails/blob/master/docs/upgrading/upgrading-react-on-rails.md Runs the Ruby bundle update to fetch the new gem version and installs updated npm packages. These commands refresh both server‑side and client‑side dependencies after modifying Gemfile and package.json. Execute them before regenerating configuration files. ```bash bundle update react_on_rails npm install ``` -------------------------------- ### Run React on Rails install generator using Rails command Source: https://github.com/shakacode/react_on_rails/blob/master/docs/upgrading/upgrading-react-on-rails.md Executes the React on Rails install generator to create or update configuration files after upgrading. This command should be run after updating gem and npm dependencies. It prepares the project for the new version's defaults. ```bash rails generate react_on_rails:install ``` -------------------------------- ### Deploying to Heroku and Opening App (Bash) Source: https://github.com/shakacode/react_on_rails/blob/master/docs/deployment/heroku-deployment.md Commits changes, pushes to Heroku master branch, and opens the live app in browser. Purpose: Final deployment step after configurations. Dependencies: Git remote set, all files committed; Input: Local repo changes; Output: Deployed app URL; Limitation: Assumes master branch; use main if applicable. ```bash git add -A git commit -m "Changes for Heroku" git push heroku master ``` ```bash heroku open ``` -------------------------------- ### Get CSRF Token and Headers in JavaScript Source: https://context7.com/shakacode/react_on_rails/llms.txt Provides methods using the `react-on-rails` library to retrieve the CSRF token and construct request headers for authenticated API calls. It includes examples for getting the token, generating headers with custom content types, and making a POST request with the correct authentication. ```javascript import ReactOnRails from 'react-on-rails'; // Get CSRF token const token = ReactOnRails.authenticityToken(); // Returns: "abc123..." or null // Get headers with CSRF token for fetch requests const headers = ReactOnRails.authenticityHeaders({ 'Content-Type': 'application/json', }); // Returns: { // 'X-CSRF-Token': 'abc123...', // 'X-Requested-With': 'XMLHttpRequest', // 'Content-Type': 'application/json' // } // Example: Making authenticated API request async function createPost(data) { const response = await fetch('/api/posts', { method: 'POST', headers: ReactOnRails.authenticityHeaders({ 'Content-Type': 'application/json', }), body: JSON.stringify(data), }); return response.json(); } ``` -------------------------------- ### Implement HelloWorldController in Ruby Source: https://github.com/shakacode/react_on_rails/blob/master/docs/core-concepts/auto-bundling-file-system-based-automated-bundle-generation.md Rails controller handling index and editor actions. Sets props for HelloWorld and HeavyMarkdownEditor components. Depends on ApplicationController; inputs are HTTP requests, outputs instance variables for views; no limitations noted. ```rb class HelloWorldController < ApplicationController def index @hello_world_props = { name: 'Auto-Registration' } end def editor @editor_props = { initialContent: "# Welcome to the Heavy Editor\n\nThis component demonstrates:\n- Dynamic imports for SSR\n- Bundle splitting\n- Automatic CSS loading" } end end ``` -------------------------------- ### Traditional Manual Structure Example Source: https://github.com/shakacode/react_on_rails/blob/master/docs/getting-started/project-structure.md Shows the directory layout for the traditional manual structure in React on Rails. This approach requires explicit webpack entry points and manual registration of components. ```text app/javascript/ ├── bundles/ │ └── HelloWorld/ │ ├── components/ │ │ └── HelloWorld.jsx │ └── startup/ │ └── registration.js # Manual ReactOnRails.register() └── packs/ └── hello-world-bundle.js # Webpack entry point ```