Skip to content

Instantly share code, notes, and snippets.

View vmcilwain's full-sized avatar

Vell vmcilwain

  • College Park, MD
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 / application.rb
Last active March 30, 2020 20:17
Starting a custom form builder in rails 6
module SomeApp
class Application < Rails::Application
...
config.paths.add Rails.root.join('lib').to_s, autoload: true
end
end
@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 / posts_helper.rb
Created October 31, 2019 13:14
[minitest] Test view code that use pundit policies
module PostsHelper
def edit_link
link_to :Edit, edit_post_path(@post), class: 'btn btn-sm btn-dark' if policy(@post).update?
end
end
@vmcilwain
vmcilwain / ransack_search_application_layout.rb
Created October 22, 2019 18:10
[Rails] Ransack search form in application layout
=form_with url: path, class: 'form-inline my-2 my-lg-0', local: true, method: :get do |f|
=f.text_field :"q[subject_or_body_cont]", class: 'form-control mr-sm-2', 'aria-label' => 'Search', placeholder: 'Search'
=f.submit 'Search', class: 'btn btn-secondary my-2 my-sm-0'
@vmcilwain
vmcilwain / linkedin_article_post.rb
Created October 2, 2019 15:01
Post/Share an article to LinkedIn via HTTParty
# Post/Share article
# via HTTParty
# the needed headers
headers = {
"Content-Type" => "application/json",
"x-li-format" => "json",
"X-Restli-Protocol-Version" => "2.0.0",
"Authorization" => "Bearer Access-Token"
}
@vmcilwain
vmcilwain / autocomplete_input.jsx.coffee
Last active April 26, 2019 17:15
React coffescript autocomplete input using datalist, modulejs, underscore, jquery. Not using ES6.
# Shouldn't be difficult to convert to ES6
# JQuery is used for the API call ONLY. I did this because I had to. DON'T DO THIS!
# Note: additionalInfoOptions is used to store additional data about the record. If data is
# coming and going from the same interface its should not be needed. This was not case of writing this code.
modulejs.define 'slzr/react/autocomplete_input',
['react', 'prop-types', 'underscore', 'jquery'],
(React, PropTypes, _, $) ->
class AutocompleteInput extends React.Component
@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 / submit-checkbox-as-hash.rb
Last active November 7, 2018 18:05
[Rails] Submit multiple checkboxes as a hash :id => boolean
# In the rails controller something like:
def _params
params.permit(:param1, :param2).tap do |whitelisted|
# because submitting objects is optional
(whitelisted[:objects] = params[:objects]) if params[:objects]
end
end
# summary_params['objects'] => {'object.id' => 'boolean-valu'}