概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Automatically cast params with the Rails Attributes API | Boring Rails: Skip the bullshit and ship fast 原文公開日: 2021-02-15 著者: Matt Swanson サイト: Boring Rails 日本語タイトルは内容に即したものにしました。 Railsアプリでは、ロジックを抽出してPORO(Plain-Old Ruby Object)にすることがよく行われます。しかしコントローラでparamsから直接これらのオブジェクトにデータを渡していることも多く、その場合はデータが文字列になってしまいます。 class SalesReport attr_accessor :start_date, :end_date, :min
![Railsの技: Attributes APIでPOROの属性を自動的にキャストする(翻訳)|TechRacho by BPS株式会社](https://cdn-ak-scissors.b.st-hatena.com/image/square/2611f759e265c4587e0a69bf9a946038ccd91384/height=288;version=1;width=512/https%3A%2F%2Ftechracho.bpsinc.jp%2Fwp-content%2Fuploads%2F2021%2F04%2Frails_tips_attributes_api_poro_autocasts_eyecatch-min.png)