Quantcast
Channel: Active Recordの記事一覧|TechRacho by BPS株式会社
Browsing all 68 articles
Browse latest View live

Image may be NSFW.
Clik here to view.

belongs_to polymorphicで、モデル名が存在しない場合

社内で質問されたので回答を書いておきます。 以下のようなモデルがあったとき、attachable_typeに存在しないモデル名(たとえば”Hoge”)が入っていたらどのような挙動をするのか? class AttachedImage < ActiveRecord::Base belongs_to :attachable, :polymorphic => true end...

View Article


Image may be NSFW.
Clik here to view.

[Rails 4.0] ActiveRecordのコールバックが呼ばれる順番まとめ

ActiveRecordにはコールバックがたくさんあります。 実行順序がよくわからなくなるので、Rails 4が出たことだし改めてまとめてみました。 ※ActiveRecord::Callbacksのヘッダコメントに全部書いてあります 使うモデル まずは、このようなクラスを作りました。 class Work < ActiveRecord::Base callbacks = %w(before...

View Article


Image may be NSFW.
Clik here to view.

ActiveRecordの便利機能previous_changes

ActiveRecordには便利なprevious_changesというメソッドがあります。 割と知名度が低いので、ここで使い方をご紹介します。 (08/26追記) はてブでご指摘(?)頂きましたが、正確にはActiveRecordではなくActiveModel::Dirtyの機能です。 まずはchanges previous_changesの前に基本のchangesです。...

View Article

Image may be NSFW.
Clik here to view.

肥大化したActiveRecordモデルをリファクタリングする7つの方法(翻訳)

こんにちは、hachi8833です。今回は、自分が知りたかった、ActiveRecordモデルのリファクタリングに関する記事を翻訳いたしました。1年前の記事なのでRails 3が前提ですが、Rails 4でも基本的には変わらないと思います。リンクは可能なものについては日本語のものに置き換えています。...

View Article

Image may be NSFW.
Clik here to view.

代理キーとナチュラルキー

こんにちは、未だ勉強中のhachi8833です。 最近読んだ「楽々ERDレッスン (CodeZine BOOKS)...

View Article


Image may be NSFW.
Clik here to view.

Rails tips: Active Recordの`#from`を使ってorderとdistinctを1つのクエリにする(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Ruby on Rails / ActiveRecord - order with distinct in one query 原文公開日: 2018/01/17 著者: Paweł Dąbrowsk Rails tips: Active Recordの#fromを使ってorderとdistinctを1つのクエリにする(翻訳)...

View Article

Image may be NSFW.
Clik here to view.

Rails tips: カスタムバリデータクラスを作る(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Ruby on Rails / Validations - build your own custom validator 原文公開日: 2018/01/11 著者: Paweł Dąbrowsk Rails tips: カスタムバリデータクラスを作る(翻訳)...

View Article

Image may be NSFW.
Clik here to view.

Rails tips: ActiveRecord count系機能の基本と応用(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Ruby on Rails / ActiveRecord - basic and advanced counting 原文公開日: 2018/01/15 著者: Paweł Dąbrowsk Rails tips: ActiveRecord count系機能の基本と応用(翻訳) Active...

View Article


Image may be NSFW.
Clik here to view.

Rails tips: `to_sql`でクエリをSQLに変換する(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Ruby on Rails / ActiveRecord - turn every query to a sql code 原文公開日: 2018/01/18 著者: Paweł Dąbrowsk Rails tips: to_sqlでクエリをSQLに変換する(翻訳)...

View Article


Image may be NSFW.
Clik here to view.

Rails tips: ActiveRecordのトランザクションの概要(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Ruby on Rails / ActiveRecord - transactions overview 原文公開日: 2018/01/23 著者: Paweł Dąbrowsk Rails tips: ActiveRecordのトランザクションの概要(翻訳)...

View Article

Image may be NSFW.
Clik here to view.

Rails tips: トランザクションをネストする(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Learn how to use nested transactions in a Ruby on Rails application 原文公開日: 2018/02/02 著者: Paweł Dąbrowsk Rails tips: トランザクションをネストする(翻訳) Ruby on...

View Article

Image may be NSFW.
Clik here to view.

Rails: スコープをモデルの外でチェインするのはやめておけ(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Say no to chained scopes! 原文公開日: 2015/06/24 著者: Jeroen Weeink サイト: Crafting Ruby Rails: スコープをモデルの外でチェインするのはやめておけ(翻訳)...

View Article

Image may be NSFW.
Clik here to view.

Hanamiフレームワークに寄せる私の想い(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: My thoughts on Hanami - Ryan Bigg 原文公開日: 2018/03/07 著者: Ryan Bigg — Ryan Bigg氏はRailsのcontributorであると同時にCulture...

View Article


Image may be NSFW.
Clik here to view.

ActiveRecordのtouchを`no_touching`で一時的に無効にする(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Rails Quick Tips: Temporarily Disabling Touching with ActiveRecord.no_touching - Karol Galanciak - Ruby on Rails and Ember.js consultant 原文公開日: 2018/02/25 著者: Karol...

View Article

Image may be NSFW.
Clik here to view.

Rails tips: self JOIN時のテーブル名を工夫する(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Ruby on Rails / ActiveRecord - tables naming in a self join 原文公開日: 2018/01/19 著者: Paweł Dąbrowsk Rails tips: self JOIN時のテーブル名を工夫する(翻訳)...

View Article


Image may be NSFW.
Clik here to view.

Ruby/Railsのプロ開発者としての5年間を振り返る(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: 5 years of professional Ruby and Rails development - My Reflections - Karol Galanciak - Ruby on Rails and Ember.js consultant 原文公開日: 2017/08/27 著者: Karol Galanciak...

View Article

Image may be NSFW.
Clik here to view.

Railsのワナ: モデルでbooleanメソッドをオーバーライドするな(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Traps on Rails - Overriding boolean methods in models - Karol Galanciak - Ruby on Rails and Ember.js consultant 原文公開日: 2017/11/26 著者: Karol Galanciak Railsのワナ:...

View Article


Image may be NSFW.
Clik here to view.

RSpecのexampleや失敗時のメッセージをわかりやすくするコツ(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Cleaner RSpec examples and failure messages 原文公開日: 2015/12/25 著者: Jeroen Weeink サイト: Crafting Ruby RSpecのexampleや失敗時のメッセージをわかりやすくするコツ(翻訳)...

View Article

Image may be NSFW.
Clik here to view.

Rails: ActiveRecord::Relationで生SQLは避けよう(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Avoid Writing SQL When Using ActiveRelation - Andy Croll 原文公開日: 2018/02/18 著者: Andy Croll 訳注: 原文のActiveRelationは訳文でActiveRecord::Relationに変更してあります。 Rails:...

View Article

Image may be NSFW.
Clik here to view.

Rails: モデルの外では名前付きスコープだけを使おう(翻訳)

概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Only use named scopes outside models - Andy Croll 原文公開日: 2018/03/04 著者: Andy Croll Rails: モデルの外では名前付きスコープだけを使おう(翻訳)...

View Article
Browsing all 68 articles
Browse latest View live