Goals: Add links that are reasonable and good explanations of how stuff works. No hype and no vendor content if possible. Practical first-hand accounts of models in prod eagerly sought.
![Screenshot 2023-12-18 at 10 40 27 PM](https://private-user-images.githubusercontent.com/3837836/291468646-4c30ad72-76ee-4939-a5fb-16b570d38cf2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk5OTU2ODYsIm5iZiI6MTcxOTk5NTM4NiwicGF0aCI6Ii8zODM3ODM2LzI5MTQ2ODY0Ni00YzMwYWQ3Mi03NmVlLTQ5MzktYTVmYi0xNmI1NzBkMzhjZjIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDNUMDgyOTQ2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OWJlYmJmMTUzOTE5MzEyODM2NWUxOWE0MDZlZjgxYzhiNzcwYjg4YjcwYjFhMGM4YmYwNThkM2FkYTZjNDM0NCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.SIA61f7WRXxCioTfyw816a7HqFnoLelA2ZgXuPuYrMY)
# frozen_string_literal: true | |
module Fingerprinting | |
def full_fingerprint | |
generate_fingerprint( | |
ip_fingerprint, | |
browser_fingerprint | |
) | |
end |
while bundle exec rake test; do :; done |
namespace :db do | |
desc 'reset the database by dropping the schema' | |
task complete_reset: :environment do | |
raise unless Rails.env.local? | |
FileUtils.rm_f('db/schema.rb') | |
Rake::Task['db:drop'].invoke | |
Rake::Task['db:create'].invoke | |
Rake::Task['db:migrate'].invoke | |
Rake::Task['db:seed'].invoke |
# Prompt: | |
What’s your most elegant Ruby code that does this: | |
* takes an array of strings and a target string | |
* if the target string is not in the array, return the array | |
* if the target string is in the array, return the array with the target string moved from its position to the end of the array. | |
What’s your most elegant Ruby code that does this: | |
* takes an array of strings and a target string |
This guide will walk you through adding a ChatGPT-like messaging stream to your Ruby on Rails 7 app using ruby-openai, Rails 7, Hotwire, Turbostream, Sidekiq and Tailwind. All code included below!
Want more content like this, for free? Check out my free book, RailsAI!
def self.included(base) | |
base.instance_variable_set(:@count, 0) unless base.instance_variable_defined?(:@count) | |
base.instance_variable_set(:@count, base.instance_variable_get(:@count) + 1) | |
puts base.name if base.instance_variable_get(:@count) > 1 | |
end |
# frozen_string_literal: true | |
# ActiveRecord::Enum validation in Rails API | |
# https://medium.com/nerd-for-tech/using-activerecord-enum-in-rails-35edc2e9070f | |
module EnumValidatable | |
extend ActiveSupport::Concern | |
class_methods do | |
def validatable_enum(*enums_to_fix) | |
enums_to_fix.each do |element| |
on: | |
workflow_call: | |
inputs: | |
deploy_target: | |
description: 'Deploy target' | |
required: true | |
type: string | |
default: 'production' | |
secrets: | |
GH_TOKEN: |
# spec/system/support/login_helpers.rb | |
# See this blog post for setup guide: https://evilmartians.com/chronicles/system-of-a-test-setting-up-end-to-end-rails-testing | |
module LoginHelpers | |
def login_as(user) | |
# Craft session cookie to make request authenticated (to pass even routing constraints) | |
# Compilation of these: | |
# - https://dev.to/nejremeslnici/migrating-selenium-system-tests-to-cuprite-42ah#faster-signin-in-tests | |
# - https://turriate.com/articles/2011/feb/how-to-generate-signed-rails-session-cookie | |
# - https://github.com/rails/rails/blob/43e29f0f5d54294ed61c31ddecdf76c2e1a474f7/actionpack/test/dispatch/cookies_test.rb#L350 |