Skip to content

Instantly share code, notes, and snippets.

@glaucocustodio
glaucocustodio / short_variable_name.rb
Created July 10, 2024 14:20
custom rubocop cop for checking if variable names are too short
# frozen_string_literal: true
# put this file at .rubocop/cop/naming/short_variable_name.rb
# then ensure you have the following in .rubocop.yml:
#
# require:
# - .rubocop/cop/naming/short_variable_name.rb
#
# Naming/ShortVariableName:
# Enabled: true
@glaucocustodio
glaucocustodio / disable_with_controller.js
Last active April 23, 2025 14:14
a Stimulus controller to disable elements on click since Rails 7.0 has dropped UJS (so `data-disable-with` is no longer available)
import { Controller } from '@hotwired/stimulus'
/*
Disable a button when it is clicked
Ps: Rails 7.0 has dropped UJS, so `data-disable-with` is no longer available
Example usage:
= button_to 'Confirm', foo_path, method: :post, class: "btn btn-warning", data: {controller: 'disable-with', 'disable-with-content-value' => 'Confirming...'}