class Comment < ApplicationRecord
belongs_to :post, touch: true
belongs_to :author, class_name: "User"
validates :body, presence: true, length: { maximum: 10_000 }
@props(['type' => 'info', 'dismissible' => false])
@php
$classes = [
'info' => 'bg-blue-100 border-blue-500 text-blue-700',
'success' => 'bg-green-100 border-green-500 text-green-700',
class ProductsController < ApplicationController
def index
@products = Product
.includes(:category)
.order(created_at: :desc)
.page(params[:page])
class CreateUserStatsView < ActiveRecord::Migration[6.1]
def up
execute <<-SQL
CREATE VIEW user_stats AS
SELECT
users.id AS user_id,
from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse_lazy
from .models import Post
from .forms import PostForm
from django.core.exceptions import PermissionDenied
class UserOwnershipMixin:
"""Ensure the object belongs to the current user."""
<div class="settings-layout">
<nav class="settings-sidebar">
<h2>Settings</h2>
<ul>
<% settings_sections.each do |section| %>
<li class="<%= "active" if current_page?(section.path) %>">
class CommentsController < ApplicationController
before_action :set_post
def create
@comment = @post.comments.build(comment_params)