Skip to content

Instantly share code, notes, and snippets.

View usutani's full-sized avatar

Yasuhiro Usutani usutani

  • Kobe, Hyogo, Japan
View GitHub Profile

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
@usutani
usutani / Procfile.dev
Last active January 6, 2022 12:22
Rails: 10通のメールを3通毎に10秒以上時間を空けて送信する
web: bin/rails server -p 3000
redis: redis-server /usr/local/etc/redis.conf
worker: bundle exec sidekiq -q mailers
@usutani
usutani / 写経.txt
Created December 26, 2021 07:26
Rails 7: The Demo
macOS 11.6
rails 7.0.0
brew install vips
brew install redis
redis-server /usr/local/etc/redis.conf
00:00 Scaffolding
rails new demo
cd demo
@usutani
usutani / README.md
Last active October 26, 2021 13:03
shared.erb --- turbo_stream create error_explanation
mkdir app/views/shared
touch app/views/shared/_turbo_stream_error_explanation.erb
@usutani
usutani / README.md
Created October 16, 2021 01:51
stimulus reset_form フォームのリセット
bin/rails g stimulus reset_form
<% form_data = { controller: "reset-form", action: "turbo:submit-end->reset-form#reset" }%>
<%= form_with model: @message, data: form_data do |form| %>
  <%= form.text_field :body %>
  <%= form.submit %>
&lt;% end %&gt;