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
# Gemfile
gem 'view_component'
# app/components/button_component.rb
class ButtonComponent < ViewComponent::Base
VARIANTS = %w[primary secondary danger].freeze
class WebhookSignature
class VerificationError < StandardError; end
TOLERANCE = 300 # seconds
def initialize(payload:, header:, secrets:)
class CreateComments < ActiveRecord::Migration[6.1]
def change
create_table :comments do |t|
t.references :commentable, polymorphic: true, null: false
t.references :author, null: false, foreign_key: { to_table: :users }
t.text :body, null: false
class DashboardMetrics
include ActiveModel::Model
attr_reader :account
def initialize(account)
class AddressForm
include ActiveModel::Model
include ActiveModel::Attributes
attribute :line1, :string
attribute :line2, :string
class CommentsController < ApplicationController
before_action :set_post
def new
@comment = @post.comments.build
end
module RequestStore
def self.store
Thread.current[:request_store] ||= {}
end
def self.fetch(key)
class ImportRun < ApplicationRecord
enum status: { pending: 0, running: 1, completed: 2, failed: 3 }
def percent
return 0 if total.to_i.zero?
[(processed.to_f / total * 100).round, 100].min
class LikesController < ApplicationController
before_action :set_post
def create
@like = current_user.likes.create!(post: @post)
respond(liked: true)
class AddSlugToPosts < ActiveRecord::Migration[7.1]
def change
add_column :posts, :slug, :string, null: false
add_index :posts, :slug, unique: true
end
end
module Posts
class CreateService
def initialize(author:, params:)
@author = author
@params = params
end