Skip to content

Instantly share code, notes, and snippets.

View vmcilwain's full-sized avatar

Vell vmcilwain

View GitHub Profile
@vmcilwain
vmcilwain / migrating from import maps to esbuild and bootstrap after implementing action text.md
Created January 12, 2023 15:12
How I migrated from import maps to esbuild and bootstrap after implementing action text

Found the following instructions that got me to the point where esbuild replaced import maps and bootstrap was installed.

https://mixandgo.com/learn/ruby-on-rails/how-to-install-bootstrap

You will find that even after fixing the Javascript issues Javascript still does not work. When looking in the log files I saw there were issues with trix loading as well as issues with importing stimulus controllers.

What I ended up doing was modifying package.json and add the following:

"@rails/actiontext": "^7.0.4",
@vmcilwain
vmcilwain / paranoid_uniqueness_validator.rb
Created January 23, 2020 19:48
Custom validator to allow creation of a record with duplicate content if it has been flagged as deleted.
# Custom validator to allow for duplicate content on an attribute in a class using acts_as_paranoid gem.
#
# Scenario:
# A user can create a record with an attribute with given content 'test'
# if a previous record with that attribute/content does not exist or if it does exist but was flagged as deleted (deleted_at IS NOT NULL)
#
# Usage:
# validates :attribute, paranoid_uniqueness: true
# or
# validates :attribute, paranoid_uniqueness: { scope: platform_id, message: 'custom message }
@vmcilwain
vmcilwain / disable_trix_toobar.rb
Created December 27, 2018 05:41
Disable trix editor toolbar in rails
# This works with the'trix-rails' gem. No reason it shouldn't work with basecamp/trix
# Code needs to have its on toobar specified. In my case I used toobar: :no_bar
=f.trix_editor :prompt_text, toolbar: :no_toolbar
# This creates the auto expanding text area without a toobar.
@vmcilwain
vmcilwain / rails_6_0_alpha.txt
Last active November 26, 2021 21:42
Steps to install rails 6.0 alpha
Pre reqs:
I installed these using homebrew
* nodejs
* yarn
Create an application directory manually
$ mkdir app_name
@vmcilwain
vmcilwain / icheck_helpers.rb
Last active December 13, 2018 16:28
[Capybara] iCheck checkbox helper methods (using JQuery)
# iCheck helper methods
def check_checkbox(attribute=:name, value)
evaluate_script "$(\":checkbox[#{attribute}='#{value}']\").prop('checked', true).iCheck('update');"
end
def uncheck_checkbox(attribute=:name, value)
evaluate_script "$(\":checkbox[#{attribute}='#{value}']\").prop('checked', false).iCheck('update');"
end
# above can be refactored_to
@vmcilwain
vmcilwain / serialize_strong_parameter.rb
Last active August 22, 2019 14:30
[Rails] Add serialized data to strong parameters
# Where data is a hash of predefined keys
# This example also shows at the end another hash inside of data
params.permit(
:date_range,
:email,
:enabled,
:id,
:limit,
:match,
:send_day,
@vmcilwain
vmcilwain / scan_and_verify.rb
Last active February 5, 2019 15:23
[Ruby] Email address scanner and verify
# scan for email addresses
text-variable.scan(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i)
=> ['[email protected]', 'user2@domain']
# Verify email addresses
a = Mail::Address.new('Foo Bar <[email protected]>')
a.address
=> "[email protected]"
@vmcilwain
vmcilwain / string_to_boolean.rb
Created June 14, 2018 14:12
Rails 3 casting a string value into a boolean
ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
# Values for true:
# 1, "1", "t", "T", "true", "TRUE", true, "on", "ON"
# Values for false:
# 0, "0", "n", "N", "false", "FALSE", false, "off", "OFF"
@vmcilwain
vmcilwain / main_app_example.rb
Last active June 4, 2018 14:03
Rails 4.2.0 Engine RSpec main app routing
# spec/support/main_app.rb
module MainAppRoute
def main_app
Rails.application.class.routes.url_helpers
end
end
# In spec/rails_helper
RSpec.config do |config|
config.include MainAppRoute
@vmcilwain
vmcilwain / disable_links.coffee
Created May 29, 2018 13:38
Disable links with a data attribute named action that ends with `_export_action`