class ArticlesController < ApplicationController
def index
# Bounded queries: without preload, article.author in the view raises.
@articles = Article
.published
.preload(:author, :tags)
import { Controller } from "@hotwired/stimulus"
import { NotificationsApi } from "notifications_api"
export default class extends Controller {
static targets = ["notification"]
static values = {
class Comment < ApplicationRecord
belongs_to :post
belongs_to :author, class_name: "User"
validates :body, presence: true
production:
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS", 5) %>
timeout: 5000
checkout_timeout: 5
class ProjectsController < ApplicationController
def create
@project = Project.new(project_params)
if @project.save
response.set_header('Turbo-Location', project_url(@project))
class AddMetadataToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :metadata, :jsonb, default: {}, null: false
add_index :users, :metadata, using: :gin
end
end
class LikesController < ApplicationController
before_action :set_post
def create
@like = @post.likes.find_or_create_by(user: current_user)
class CircuitBreaker
class CircuitOpenError < StandardError; end
def initialize(name, redis: Redis.current, failure_threshold: 5, failure_window: 60, cooldown: 30)
@key = "circuit:#{name}"
@redis = redis