- You MUST NOT try and generate a Rails app from scratch on your own by generating each file. For a NEW app you MUST use
rails newfirst to generate all of the boilerplate files necessary. - Create an app in the current directory with
rails new . - Use Tailwind CSS for styling. Use
--css tailwindas an option on therails newcall to do this automatically. - Use Ruby 3.2+ and Rails 8.0+ practices.
- Use the default Minitest approach for testing, do not use RSpec.
- Default to using SQLite in development.
rails newwill do this automatically but take care if you write any custom SQL that it is SQLite compatible. - An app can be built with a devcontainer such as
rails new myapp --devcontainerbut only do this if requested directly. - Rails apps have a lot of directories to consider, such as app, config, db, etc.
- Adhere to MVC conventions: singular model names (e.g., Product) map to plural tables (products); controllers are plural.
- Guard against incapable browsers accessing controllers with `allo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # parallel-agent: Run multiple Claude Code agents in parallel using git worktrees | |
| # | |
| # WHY THIS SCRIPT EXISTS: | |
| # 1. Run multiple Claude Code agents simultaneously for different tasks | |
| # 2. Execute long-running agent tasks in a non-blocking way | |
| # 3. Work on multiple features/branches without switching contexts | |
| # 4. Isolate agent work to prevent conflicts between concurrent tasks | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from IPython.core.magic import register_cell_magic | |
| import subprocess | |
| import os | |
| import re | |
| from sys import stderr | |
| import shutil | |
| import atexit | |
| class RubySession: | |
| def __init__(self): |
In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.
Some examples:
7 # integer literalThis example shows how to process a JSON response from the OpenAI Chat API in streaming mode.
- We are looking for a JSON key named
questionswhich contains an array of JSON objects with the keysquestionandanswer - As each question and answer pair is found we process it via the end_object block.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Example of using SQLite VSS with OpenAI's text embedding API | |
| # from Ruby. | |
| # Note: Install/bundle the sqlite3, sqlite_vss, and ruby-openai gems first | |
| # OPENAI_API_KEY must also be set in the environment | |
| # Other embeddings can be used, but this is the easiest for a quick demo | |
| # More on the topic at | |
| # https://observablehq.com/@asg017/introducing-sqlite-vss | |
| # https://observablehq.com/@asg017/making-sqlite-extension-gem-installable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # frozen_string_literal: true | |
| module Packer | |
| # A special packer class for globally identifiable objects. It takes a global ID and packs it as a String, then rehydrates it as a GlobalID lookup. | |
| class GloballyIdentifiable | |
| def self.from_pack(uri) | |
| GlobalID::Locator.locate(uri) | |
| end | |
| def initialize(identifiable) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| enum Environment: String { | |
| case development, staging, production | |
| } | |
| extension Environment { | |
| static var current: Environment { | |
| if isAppStore { | |
| return .production |
This guide will walk you through adding a ChatGPT-like messaging stream to your Ruby on Rails 7 app using ruby-openai, Rails 7, Hotwire, Turbostream, Sidekiq and Tailwind. All code included below!
Want more content like this, for free? Check out my free book, RailsAI!
- Follow me on Twitter for more Ruby AI at https://twitter.com/alexrudall
- Released under the MIT License - use as you wish :)
NewerOlder
