Skip to content

Instantly share code, notes, and snippets.

View adrienpoly's full-sized avatar
I may be slow to respond.

Adrien Poly adrienpoly

I may be slow to respond.
View GitHub Profile
adrienpoly / attached_validator.rb
Created October 26, 2023 06:56 — forked from donnfelker/attached_validator.rb
Custom Active Storage Validator
class AttachedValidator < ActiveModel::EachValidator
# Active Storage validator to ensure that an attachment is attached.
# usage:
# validates :upload, attached: true
def validate_each(record, attribute, _value)
return if record.send(attribute).attached?
errors_options = {}
adrienpoly / has_many_attached.rb
Created October 26, 2023 06:55 — forked from fractaledmind/has_many_attached.rb
Vanilla Rails isomorphic attachment validations
# /app/models/concerns/has_many_attached.rb
module HasManyAttached
extend ActiveSupport::Concern
class_methods do
def has_many_attached(name, dependent: :purge_later, service: nil, strict_loading: false, **options)
super(name, dependent: :purge_later, service: nil, strict_loading: false)
if options[:file_types].any?
validate "validate_#{name}_file_types".to_sym
adrienpoly / test.csv
Last active August 22, 2022 15:15 — forked from RonanLOUARN/test.csv
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Le Merveilleux;Écriture Libre;16;24;0;34;50;0;#FFBB87;Irène Bonacina;-;;;;NON
La Science Fiction;Écriture Libre;16;24;50;57;12;0;#9378A7;Taty Vovchek;-;;;;NON
La Bergère et le Ramoneur;Forêt Enchantée;19;29;0;32;84;0;#FFAD29;Irène Bonacina;Hans Christian Andersen;;
adrienpoly / pdfx.rb
Created January 25, 2022 05:43 — forked from fidothe/pdfx.rb
Worked example for creating a PDF/X-1a:2003 document with Prawn
require 'prawn'
require 'prawn/measurements'
# I have a small collection of links to the resources I used to figure all
# this out:
module PDFX
class PageBox
include Prawn::Measurements
attr_reader :bleed_mm
adrienpoly /
Created September 24, 2021 09:32
Upgrade to Stimulus 3 recommandations

To upgrade to Stimulus 3.0 and minimize the side effects of the npm package name change here is my suggestion

# add the proxy package
yarn add stimulus

# add the new @hotwired/stimulus package
yarn add @hotwired/stimulus

# add the dedicated package for the Webpack helpers
adrienpoly / application.html.erb
Last active March 22, 2024 08:14
Capybara / Stimulus test helper to ensure JS is ready when test starts
<!DOCTYPE html>
<body data-controller="js">
<%= yield %>
adrienpoly / static.js
Last active October 20, 2020 16:40
accessing static values from a class instance
class A extends Controller {
static targets = ["a", "b"]
connect() {
A.targets // -> ["a", "b"]
export default class extends Controller {
static targets = ["a", "b"]
adrienpoly / index.html
Created May 8, 2019 09:05
Fetch & the gang
<!DOCTYPE html>
<meta charset="UTF-8">
<title>Playground - JavaScript 101</title>
<style media="screen">
.red { color: red; }
<link rel="stylesheet"
adrienpoly /
Created October 4, 2018 13:08
Step by Step guide to test Rails ActiveText

Step by Step guide to test Rails ActiveText

You might have seen the video of DHH about ActionText upcoming feature in Rails 6. This is a step by step guide for creating the exact same example as in the video.

⚠️ If like me you never ran an edge version of Rails before and wonder how to do it then this is for you

Create a new app from the Edge version of Rails

  1. Clone the Rails repo