Skip to content

Instantly share code, notes, and snippets.

View usutani's full-sized avatar

Yasuhiro Usutani usutani

  • Kobe, Hyogo, Japan
View GitHub Profile

once-deploy

ONCE へ Rails アプリケーションをデプロイするスクリプト。

導入

curl -sSL https://gist.githubusercontent.com/usutani/6ac30d372f06d3d14bbe396f3229d799/raw/once-deploy.rb \
  -o bin/once-deploy && chmod +x bin/once-deploy

study_drag 導入手順書

概要

writebook (MIT License) のドラッグ&ドロップ並び替え機能 (Arrangement) を参考にした、シンプルな Rails アプリです。

同一階層の Item をドラッグ&ドロップまたはキーボード操作で並び替えられます。

前提: writebook リポジトリ (https://github.com/basecamp/writebook) にアクセスできること。

項目 SQLite FTS5 MySQL (Trilogy)
ステミングのタイミング FTS5内部で自動 保存時と検索時の両方
保存されるcontent 元の文章 ステミング済み文章
トークン化 FTS5内部 アプリ側で実施(gsub + split)
ハイライト FTS5の highlight() Rubyの Search::Highlighter
@usutani
usutani / fizzy_dialog_css.md
Last active April 4, 2026 02:44
fizzy_dialog_css

How to deploy a Rails 7.1 app with Postgres and Kamal on a single server

I think you have looked at the tutorial from Mr. Heinemeier Hansson at least once or twice and have a similar setup.

application

  • ruby 3.2.2
  • rails 7.1.3.2
  • postgresql 15

server

@usutani
usutani / launch.json
Created May 1, 2023 06:41
VS Code --- rdbg --- Debug Rails
{
"version": "0.2.0",
"configurations": [
{
"type": "rdbg",
"name": "Debug Rails",
"request": "launch",
"cwd": "${workspaceRoot}",
"script": "bin/rails server",
"args": [],
@usutani
usutani / action_mailer_gem.rb
Last active April 30, 2023 08:31
Action Mailerのテスト用テンプレート
# frozen_string_literal: true
# https://github.com/rails/rails/blob/main/guides/bug_report_templates/generic_gem.rb
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
@usutani
usutani / has_many__distinct__through__source.rb
Last active April 22, 2023 08:31
Rails: has_many distinct through: source: の習作 https://note.com/usutani/n/n741bd5112e43
# frozen_string_literal: true
# Rails: 私の好きなコード(5)永続化とロジックを絶妙にブレンドするActive Record(翻訳)
# https://techracho.bpsinc.jp/hachi8833/2023_04_18/127103
# Topic
# has_many :entry_creators, -> { distinct }, through: :entries, source: :creator
#
# https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record_gem.rb
# Rename: Post(posts) => Topic(topics), Comment(comments) => Entry(entries)
# New: Creator(creators)
@usutani
usutani / has_many__through__class_name.rb
Last active April 22, 2023 08:47
Rails: has_many through: class_name: の習作 https://note.com/usutani/n/nb3d1fe9e085b
# frozen_string_literal: true
# Rails: 私の好きなコード(5)永続化とロジックを絶妙にブレンドするActive Record(翻訳)
# https://techracho.bpsinc.jp/hachi8833/2023_04_18/127103
# Topic
# has_many :blocked_trackers, through: :entries, class_name: "Entry::BlockedTracker"
#
# https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record_gem.rb
# Rename: Post(posts) => Topic(topics), Comment(comments) => Entry(entries)
# New: Entry::BlockedTracker(entry_blocked_trackers)
@usutani
usutani / account.rb
Last active November 12, 2022 03:50
try_account --- 更新時にnilで保存できないようにしました。
# bundle add bcrypt
# rails g scaffold Account email password_digestx
# rails db:migrate
class Account < ApplicationRecord
has_secure_password validations: false
validate do |record|
record.errors.add(:password, :blank) unless record.password_digest.present?
end
validates :password, format: { with: /\A[a-z0-9]+\z/i }, length: { in: 8..30 }, on: :create, unless: -> { password_digest.blank? }
validates :password, format: { with: /\A[a-z0-9]+\z/i }, length: { in: 8..30 }, on: :update, allow_nil: true