• Basics of Stimulus Outlets in Rails 7

    It is possible for a Stimulus Controller to have values, targets and outlets. If you have 2 (or more) separate Stimulus controllers on the same page, it is possible for controller A to see all the values and targets of controller B, from within controller A. It is assumed that...
  • Where to add the value attribute for Stimulus

    Stimulus values need to be added to the same element that defines the data-controller For example: <div data-controller="example" data-example-value="hello_there"> .... </div> This is referenced directly in their docs The value then needs to exist in the Stimulus controller: // stimulus controller file import { Controller } from "@hotwired/stimulus"; export default...
  • Compare a git diff of a single file between a branch and master, quickly

    git diff <feature_branch_name>..master -- path/to/file/name.rb This will show, in the terminal, the git diff of the file at “path/to/file/name.rb” between the branch you’re currently working on and the master branch.
  • Using the dom_id helper method

    Sometimes when writing HTML, it’d be nice to have a shortcut to create an id attribute. In Rails views there exists the dom_id helper method that does this very thing. It’s designed to be used with a collection of ActiveRecord items (for example, a collection of items from a database...
  • Creating One-to-Many Association in Rails

    Intro Quick reminder about creating a one-to-many relationship/association. What did I already know I knew that I needed to put both sides of the relationship into their respective models. The Team model needs has_many :players, and the Player model needs belongs_to :team. A migration would be needed; and that there...
  • Connect Js With Importmaps Rails7

    There was a disconnect between the documentation and the various StackOverflow and Google searches regarding this subject. So I’m writing this article. Intro This article assumes a couple of things: Using an (existing) Rails 7 project - I did this with rails v 7.0.8 The app was created using the...
  • Basic Devise setup in Rails 7 (no OmniAuth of any type)

    This article is written with the expectation that ViewComponents are being used When I have a new rails app that’s been created with a root route in the routes.rb file, I’m ready to create users. Here’s the steps needed to add Authentication using Devise in a Rails 7 app. Add...
  • Creating a Controller, an Action and a Root path in a Rails 7 app

    Creating a Rails 7 app is an easy thing to do from the command line. rails new devise-practice-1 After it’s been created, starting the rails server is also very easy to do. cd devise-practice-1 rails s This spins up the server (which is enabled by the software called Puma; You...