並び順

ブックマーク数

期間指定

  • から
  • まで

1 - 5 件 / 5件

新着順 人気順

ActiveModelの検索結果1 - 5 件 / 5件

  • Railsの技: Attributes APIでPOROの属性を自動的にキャストする(翻訳)|TechRacho by BPS株式会社

    概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: 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株式会社
    • ActiveModel::Attributesを使う - Qiita

      ここでは、Rails 5.2で導入されたActiveModel::Attributesについて紹介します。RubyのクラスにActiveRecordのカラムのような属性を加えられます。 サンプル: https://github.com/kazubon/blog-rails6-vuejs/blob/master/app/forms/entries/form.rb クラスにActiveModel::ModelとともにActiveModel::Attributesをインクルードします。 class Entries::Form include ActiveModel::Model include ActiveModel::Attributes クラスメソッドattributeに属性名と型を渡すと、attr_accessorと同じように属性が使えるようになります。指定できる型の種類については、Rai

        ActiveModel::Attributesを使う - Qiita
      • [Rails] ActiveModel::Attributesの使い方(配列化やネストしたhashの取り扱いなども) - Qiita

        Register as a new user and use Qiita more conveniently You get articles that match your needsYou can efficiently read back useful informationYou can use dark themeWhat you can do with signing up

          [Rails] ActiveModel::Attributesの使い方(配列化やネストしたhashの取り扱いなども) - Qiita
        • 【Rails】「ActiveModel::Attributes」が便利という話 - 日々の学びのアウトプットするブログ

          はじめに Rails 6.0が今年リリースされようかという今になって、Rails 5.2の新機能であるActiveModel::Attributesの便利さを知りました。 なので、今回は 「ActiveModel::Attributes」について、学んだことをアウトプットしたいと思います。 ActiveRecordの「Attribute API」 今回の話のそもそもの前提として、RailsのActiveRecordにあるAttribute APIという機能を知っておくと、話がわかりやすいと思います。 このAttribute APIがあるおかげで、ActiveRecordを操作する際にクラス属性の型を意識しなくても、指定の型へ変換してくれています。 # Userの属性の型定義 # - is_admin: boolean # - age: integer # - birthday: date

            【Rails】「ActiveModel::Attributes」が便利という話 - 日々の学びのアウトプットするブログ
          • Rails 7.1: Active Modelバリデーションのin・withinオプションでbeginless/endless rangeをサポート(翻訳)|TechRacho by BPS株式会社

            概要 元サイトの許諾を得て翻訳・公開いたします。 英語記事: Rails 7.1 allows infinite ranges for LengthValidators and Clusivity validators - BigBinary Blog 原文公開日: 2022/08/30 原著者: Ghouse Mohamed サイト: BigBinary Blog 日本語タイトルは内容に即したものにしました。 参考: 週刊Railsウォッチ20220531: バリデーションのinやwithinでbeginless/endless rangeをサポート 参考: Edge API ActiveModel::Validations::Length -- private 参考: Edge API ActiveModel::Validations::Clusivity -- private 参考:

              Rails 7.1: Active Modelバリデーションのin・withinオプションでbeginless/endless rangeをサポート(翻訳)|TechRacho by BPS株式会社
            1