- 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 therails 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveExchange | |
class Channel | |
def initialize(name:, server: ActiveExchange.server) | |
@server = server | |
@channel = name | |
@queue = Queue.new | |
@subscribe = false | |
end | |
def broadcast(message) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Anonymizer | |
include ActiveSupport::Benchmarkable | |
attr_reader :factory_names, :callbacks | |
def initialize(factory_names = nil, callbacks = {}) | |
raise ArgumentError.new("You must be in development to use the anonymizer") unless Rails.env.development? | |
require Rails.root.join("spec/factories") unless FactoryBot.factories.count > 0 | |
@factory_names = [*factory_names].compact.map(&:to_sym) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A Pipeline extension to process steps concurrently | |
# Example | |
# class ConcurrentPipeline < Pipeline | |
# include ConcurrentProcessing | |
# end | |
# | |
# MyPipeline = ConcurrentPipeline.new do |pl| | |
# pl.step ValidateInput | |
# | |
# # These steps run concurrently |
I created this to help me run benchmarks/comparisons against Universal ID, but it could serve as the foundation for a robust ETL data pipeline... and it's less than 70 LOC right now! 🤯 🚀
It handles the extract and transform parts of an ETL process and supports the following options:
only
- specify which attributes to include
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OAuth::GoogleAuthorizationsController < ApplicationController | |
CLIENT_ID = Rails.application.credentials.google.client_id | |
CLIENT_SECRET = Rails.application.credentials.google.client_secret | |
SCOPE = "openid email profile" | |
AUTHORIZATION_URL = URI("https://accounts.google.com/o/oauth2/v2/auth") | |
TOKEN_URL = URI("https://www.googleapis.com/oauth2/v4/token") | |
USER_INFO_URL = URI("https://www.googleapis.com/oauth2/v3/userinfo") | |
before_action :validate_state_token, only: :show |
This guide will walk you through adding some extra features such as the ability to underline your text, or enhance your content by adding superscripts or subscripts for annotations or Math equations.
Prerequisites: Instruction guide assumes that you have created a Rails application and installed ActionText.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
# https://github.com/rails/rails/pull/42761 | |
class Execution | |
TEST_FILE_PATH = "test/threshold_test.rb" | |
SINGLE_TEST_DURATION = 0.1 | |
attr_reader :threshold, :parallel | |
def initialize(threshold, parallel: false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias gb="git branch --sort=-committerdate --verbose --format='%(HEAD) %(color:red)%(objectname:short)%(color:reset) - %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) - %(color:green)(%(committerdate:relative))%(color:reset) %(color:blue)<%(authorname)>%(color:reset)'" | |
alias gba="gb -a" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Loggable | |
extend ActiveSupport::Concern | |
def log(message) | |
return if Rails.env.test? | |
Rails.logger.info "[#{current_timestamp}] [#{current_service_name}] #{message}\n" | |
end | |
private |
NewerOlder