Rails Console truncate the attributes
After Ruby 3, rails console will truncate the attributes, it's because `IRB.conf[:ECHO_ON_ASSIGNMENT]` is default to `:truncate`, you can...
Deploy Rails with Kamal
[https://nts.strzibny.name/deploying-rails-single-server-kamal/](https://nts.strzibny.name/deploying-rails-single-server-kamal/?ref=blog....
Rails 7 adds AudioAnalyzer to ActiveStorage
AudioAnalyzer 可以幫忙解析 audio 的 metadata [https://blog.saeloun.com/2021/06/30/rails-7-adds-audio-analyzer-to-active-storage/](https://blo...
A new DB-based queuing backend for Active Job
說是可以取代下列的各個 Gems ``` # Jobs gem "resque", "~> 2.0.0" gem "resque_supervised_fork", bc: "resque_supervised_fork" gem "resque-pool",...
Rails 7 new error reporting/handling methods
Rails 7 推出了 in house error handler 來取代大家最常使用的 `begin ... rescue` block,官方給的最簡 example looks like this: ``` Rails.error.handle(Somethi...
Rails 7 with bootstrap 5
照這個教學 https://jasonfleetwoodboldt.com/courses/stepping-up-rails/rails-7-bootstrap/
How to use Active Record Encryption without Rails credential
This post will teach you how to use Active Record Encryption with Dotenv ### Step 1: generate credential First of all, follow [officia...
DHH shares hey.com Gemfile
```rb ruby '2.7.1' gem 'rails', github: 'rails/rails' gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data # Actio...
How to sort by an given array in many different ways (in Rails with ActiveRecord with Postgres)
## 1. Use sort_by and prioritized array https://stackoverflow.com/questions/1680627/activerecord-findarray-of-ids-preserving-order/268...
Rails nested transaction
TL:DR: Best Practice: 在 nested transaction 內不要手動 `raise ActiveRecord::Rollback`, 一律使用 `save!`, `update!` 等操作,就不會有問題。 1. raise `ActiveRe...
How to extend ActiveRecord
Let's have a simple example, I want to implement a `puts_something` callback to `ActiveRecord`, whenever my object get initialzied, I wan...
Different behaviour about counter_cache between Rails6.x and Rails5.x
TL;DR: ```rb update!(somthing_id: somthing.id) # => This line will trigger counter_cache in Rails5 but not in Rails6 ``` To make it w...
How DHH write RESTful controller
常常要貼這個連結給別人但每次都忘記這篇的連結在哪,紀錄一下以後好搜尋 https://gist.github.com/dhh/10022098
ActiveStorage#attach has different return value between v5 and v6
In activestorage v5 ```rb current_user.images.attach( io: file, filename: file.original_filename, content_type: file.content_type ...
We can change ActiveStorage route_prefix in Rails 6
Usage: ```rb # config/application.rb config.active_storage.routes_prefix = '/files' ``` So instead of having route like `www.example.c...
Finally we can disable generated scope from ActiveRecord#enum in Rails 6
Usage: ```rb class Post < ApplicationRecord enum state: { draft: 0, published: 1, personal: 2 }, _scopes: false end ``` PR: https://g...
Validate JSON schema in Rails
This is an archive of my post from 2017 (revised by [@morhekil](https://twitter.com/morhekil)), original posted in [medium](https://mediu...
Using RabbitMQ and Hutch with RPC call for queue in Rails
This is an example how the author implement the RPC call using Hutch and communicate with RabbitMQ https://karolgalanciak.com/blog/2020/...
一篇在講 Ruby on Rails 的 ActiveRecord 和 Elixir Phoenix Ecto 差別的文章
一篇在講 Rails 的 ActiveRecord 和 Phoenix Ecto 差別的文章,其實主要就是表達 Model 跟 Schema 脫鉤這樣而已,另外也提到了 Model 沒有 State 所以可以更好 passing around, ex: ```elixir...
How to test with Salesforce Heroku Connect - Part 2
In my previous post [How to test with Salesforce Heroku Connect ](https://waynechu.cc/posts/290-how-to-test-with-salesforce-heroku-conne...
Rails 用 webpacker 時 compile 很慢而且很吃 memory?You're probably a over-packer lol
長話短說,就是 webpacker 會 compile **所有** 在 `japascripts/packs` 資料夾底下的東西,所以只要沒有要在 layout 裡面 include 的 file 就不要放在 packs 下面,這樣就會變快了。 Copy paste f...
Faking External Services in Tests with Adapters
Faking External Services in Tests with Adapters https://thoughtbot.com/blog/faking-external-services-in-tests-with-adapters
Unexpected behaviour for ActiveModel::Model validate and valid?
Assume we have an `FakeUser` class looks like below: ```rb class FakeUser include ActiveModel::Model include ActiveModel::Attribute...
Rails 6 ActiveStorage updates
工作上有用到 ActiveStorage,然後我又手癢想升級 Rails,所以先記錄一下 https://blog.saeloun.com/2019/11/04/rails-6-active-storage-updates.html