class PasswordResetsController < ApplicationController
before_action :find_user_by_token, only: [:edit, :update]
def create
user = User.find_by(email: params[:email]&.downcase)
# app/policies/post_policy.rb
class PostPolicy < ApplicationPolicy
class Scope < Scope
def resolve
if user.admin?
scope.all
class UserSearchQuery
def initialize(relation = User.all)
@relation = relation
end
def call(params)
class Post < ApplicationRecord
has_many :comments, dependent: :destroy
# comments_count is maintained by counter_cache on Comment#belongs_to
scope :stale_comment_counts, lambda {
class CommentsController < ApplicationController
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.build(comment_params)
@comment.author = current_user
class TransferFundsService
def initialize(from_account:, to_account:, amount:)
@from_account = from_account
@to_account = to_account
@amount = amount
end
# Gemfile
gem 'draper'
# app/decorators/user_decorator.rb
class UserDecorator < Draper::Decorator
delegate_all
class CacheNamespace
attr_reader :name
def initialize(name, store: Rails.cache)
@name = name.to_s
@store = store
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["checkbox", "selectAll", "count", "submit"]
static values = { selectedIds: Array }
class AddConstraintsToUsers < ActiveRecord::Migration[6.1]
def change
# Null constraints
change_column_null :users, :email, false
change_column_null :users, :username, false
require "sidekiq/api"
class QueueDepthGuard
class QueueSaturated < StandardError
attr_reader :queue, :depth
<div class="search-page">
<div class="search-header mb-6">
<h1 class="text-2xl font-bold mb-4">Search Posts</h1>
<%= form_with url: posts_path,
method: :get,