class ImportResult
RowError = Struct.new(:line, :messages)
attr_reader :imported, :row_errors
def initialize
class DeliveryObserver
def self.delivered_email(message)
new(message).record
end
def initialize(message)
require 'ipaddr'
require 'resolv'
uri = URI.parse(params[:url])
allowed_hosts = %w[images.example-cdn.com api.partner.com]
class PriceBreakdown < Struct.new(:subtotal_cents, :discount_cents, :tax_cents, keyword_init: true)
def initialize(*)
super
freeze
end
class LastSeenTracker
THROTTLE = 5.minutes
PENDING_KEY = "pending:last_seen".freeze
class << self
def touch(user_id, at: Time.current)
class CreateReservations < ActiveRecord::Migration[7.1]
def up
enable_extension "btree_gist" unless extension_enabled?("btree_gist")
create_table :reservations do |t|
t.references :room, null: false, foreign_key: true
# Basic exception handling
begin
result = 10 / 0
rescue ZeroDivisionError => e
puts "Error: #{e.message}"
result = nil
class CommentsController < ApplicationController
before_action :set_post
def create
@comment = @post.comments.build(comment_params)
import { StreamActions } from "@hotwired/turbo"
StreamActions.flash = function () {
const container = document.getElementById("flashes")
if (!container) return
class ButtonComponent < ViewComponent::Base
VARIANTS = {
primary: "bg-blue-600 hover:bg-blue-700 text-white",
secondary: "bg-gray-200 hover:bg-gray-300 text-gray-900",
danger: "bg-red-600 hover:bg-red-700 text-white"
}.freeze
<%= form_with url: bulk_update_orders_path, method: :patch, data: { turbo_confirm: "Update selected orders?" } do %>
<div class="batch-toolbar">
<%= select_tag :status,
options_for_select(Order.statuses.keys.map { |s| [s.humanize, s] }),
prompt: "Set status to\u2026" %>
<%= submit_tag "Apply to selected", class: "btn" %>
# Gemfile
gem 'view_component'
# app/components/button_component.rb
class ButtonComponent < ViewComponent::Base
VARIANTS = %w[primary secondary danger].freeze