Skip to content

Instantly share code, notes, and snippets.

View tabishiqbal's full-sized avatar

Tabish Iqbal tabishiqbal

  • Toronto, Ontario
View GitHub Profile
@tabishiqbal
tabishiqbal / _form.html.erb
Created February 27, 2025 00:34 — forked from lazaronixon/_form.html.erb
Dropzone.js + Stimulus + Active Storage + CSS Zero (2025)
<%= form_with(model: billboard) do |form| %>
<%= tag.div class: "dropzone", data: { controller: "dropzone", dropzone_param_name_value: "billboard[images][]", dropzone_url_value: rails_direct_uploads_url, dropzone_accepted_files_value: "image/*", dropzone_max_files_value: 3, dropzone_max_filesize_value: 0.300 } do %>
<div class="dz-default dz-message flex flex-col items-center">
<%= image_tag "upload.svg", size: 28, class: "colorize-black", aria: { hidden: true } %>
<h5 class="font-semibold mbs-4">Drop files here or click to upload.</h5>
<p class="text-sm text-subtle">Upload up to 10 files.</p>
</div>
<% end %>
<div class="inline-flex items-center mbs-2 mie-1">
@tabishiqbal
tabishiqbal / CONVENTIONS.md
Created February 12, 2025 23:50 — forked from peterc/CONVENTIONS.md
CONVENTIONS.md file for AI Rails 8 development
  • You MUST NOT try and generate a Rails app from scratch on your own by generating each file. For a NEW app you MUST use rails new first to generate all of the boilerplate files necessary.
  • Create an app in the current directory with rails new .
  • Use Tailwind CSS for styling. Use --css tailwind as an option on the rails new call to do this automatically.
  • Use Ruby 3.2+ and Rails 8.0+ practices.
  • Use the default Minitest approach for testing, do not use RSpec.
  • Default to using SQLite in development. rails new will do this automatically but take care if you write any custom SQL that it is SQLite compatible.
  • An app can be built with a devcontainer such as rails new myapp --devcontainer but only do this if requested directly.
  • Rails apps have a lot of directories to consider, such as app, config, db, etc.
  • Adhere to MVC conventions: singular model names (e.g., Product) map to plural tables (products); controllers are plural.
  • Guard against incapable browsers accessing controllers with `allo
@tabishiqbal
tabishiqbal / attached_validator.rb
Created October 26, 2023 02:27 — 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 = {}
@tabishiqbal
tabishiqbal / _form.html.erb
Last active April 2, 2025 02:48
Ruby on Rails simple multiple select using Tom-select
<%= form_with(model: product) do |form| %>
<div>
<%= form.label :name %>
<%= form.text_field :name, class: "input" %>
</div>
<div>
<%= form.label :categories %>
<%= form.collection_select :category_ids, Category.all, :id, :name, {}, {multiple: true, id: 'category-select', class: "dropdown"} %>
</div>
@tabishiqbal
tabishiqbal / trix_shrine.md
Created July 20, 2023 01:25 — forked from dpaluy/trix_shrine.md
Trix and Shrine for WYSIWYG

How to use Trix and Shrine for WYSIWYG Editing with Drag-and-Drop Image Uploading

Building It

Install and Configure Shrine and Trix Dependencies

  1. Setup Shrine:

First, add the Shrine gem to your application's Gemfile:

@tabishiqbal
tabishiqbal / slug.rb
Created August 21, 2022 16:29 — forked from Merovex/slug.rb
Create random slug
# frozen_string_literal: true
module Slug
extend ActiveSupport::Concern
def self.included(base)
base.extend ClassMethods
base.before_create :set_slug
end
def to_param
@tabishiqbal
tabishiqbal / .gitattributes
Created April 2, 2022 09:22 — forked from tpope/.gitattributes
Fewer conflicts in your Rails apps
Gemfile.lock merge=bundlelock
db/schema.rb merge=railsschema
@tabishiqbal
tabishiqbal / google-sheets-dataclip-autoupdate.md
Created October 6, 2021 18:24 — forked from aGHz/google-sheets-dataclip-autoupdate.md
Auto-updating importData of Heroku Dataclips in Google Sheets

Dataclips URLs

Dataclips has a reliable way to construct the URL of a clip's CSV version:

https://dataclips.heroku.com/<hash>-<description>.csv

Thankfully the description is irrelevant, so we can just get the hash from the web interface (looks like aujqawhjdmlbbwrqxutcpzzqyika) and add -1 at the end. Every time we change the

@tabishiqbal
tabishiqbal / _form.html.erb
Last active January 15, 2025 21:39
Ruby on Rails Tom-Select Example with Stimulus controller
<%= form_with(model: team) do |form| %>
<div>
<%= form.label :name %>
<%= form.text_field :name, class: "input" %>
</div>
<div>
<%= f.select :user_id, {}, {placeholder: "Select user"}, {class: "w-full", data: { controller: "select", select_url_value: users_path }} %>
</div>
@tabishiqbal
tabishiqbal / region_reflex.rb
Last active May 3, 2021 16:10
Stimulus Reflex populate dropdowns
class RegionReflex < ApplicationReflex
def select_state
state_id = element[:value].to_i
@state = State.find(state_id)
@state_cities = @state&.cities
end
end