Skip to content

Instantly share code, notes, and snippets.

View Mate2xo's full-sized avatar

Tim Mate2xo

  • Chantilly
View GitHub Profile
@carlosramireziii
carlosramireziii / allow_content_type.rb
Last active December 6, 2024 21:06
A validator and RSpec matcher for restricting an attachment’s content type using Active Storage
require "rspec/expectations"
RSpec::Matchers.define :allow_content_type do |*content_types|
match do |record|
matcher.matches?(record, content_types)
end
chain :for do |attr_name|
matcher.for(attr_name)
end
@carlosramireziii
carlosramireziii / attached_validator.rb
Last active April 10, 2024 11:11
A validator and RSpec matcher for requiring an attachment using Active Storage
class AttachedValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors.add(attribute, :attached, options) unless value.attached?
end
end
@nicolas-brousse
nicolas-brousse / active_admin.js
Last active May 14, 2021 18:45
Formtastic PostgreSQL Array input (inspered from https://gist.github.com/franks921/44509c65da3bea99bc49)
$('form .input.array').each(function() {
var $wrapper = $('.array-inputs', this);
var $insertArea = $(".array-input button[data-action=add]").closest(".array-input");
$(".array-input button[data-action=add]", $(this)).click(function(e) {
$('.array-input:first-child', $wrapper).clone(true).insertBefore($insertArea).find('input').val('').focus();
});
$('.array-input button[data-action=remove]', $wrapper).click(function() {
if ($('.array-input', $wrapper).length > 2) {
$(this).parent('.array-input').remove();
}
@Lukom
Lukom / email_previews.rb
Last active April 2, 2021 18:43
Preview Emails in ActiveAdmin / Rails 5.1
# app/admin/email_previews.rb
ActiveAdmin.register_page 'Email Previews' do
menu parent: 'dashboard', priority: 10
content do
div '1'
end
sidebar 'Mail Previews' do
Dir['test/mailers/previews/**/*_preview.rb'].each do |preview_path|
@ondrejbartas
ondrejbartas / how_to_setup_cypress_with_rails_app.md
Last active April 2, 2021 01:15
How to setup Cypress on Rails apps

How to setup Cypress on Rails apps

You need to update circle.yml:

machine:
  node: # add node dependency
    version:
      7.4

environment: