Skip to content

Instantly share code, notes, and snippets.

@john-hamnavoe
john-hamnavoe / rails_7_select_populate_other_field_on_form.md
Created January 4, 2023 12:37
Basic approach to having default value on field populated by selection on select box

Introduction

For example have form with select box which has list of reasons and when user selects the reason we want to populate an amount field on the form. The reason table has the amount as one of its columns. In this example we have adjusments and adjustment_reasons when user creates a new adjustment they pick reason it populates the amount with default value from the adjustment reason.

Stimulus Controller

We will create reason_controller.js in app/javascript/controllers.

@john-hamnavoe
john-hamnavoe / find_invalid_files.zsh
Last active March 15, 2025 22:49
ZSH script to identify files and folders starting/ending with space and having colon or backslash valid on Mac but problem on OneDrive
#!/bin/bash
# Ensure a folder name is provided
if [[ -z "$1" ]]; then
echo "Usage: $0 <directory> [--rename]"
echo " --rename: Replace problematic characters in filenames"
exit 1
fi
target_dir="$1"