タケユー・ウェブ日報

Ruby on Rails や Flutter といったWeb・モバイルアプリ技術を武器にお客様のビジネス立ち上げを支援する、タケユー・ウェブ株式会社の技術ブログです。

ActiveRecord で limit とか offset とかしたコレクションから条件を満たす全件数を取得する

posts = Post.where(author: author).limit(limit).offset(offset)

posts.count # => 0 ~ limit

posts.except(:limit, :offset).count # => 0 ~ 

Rails3からexceptで適用済みの条件式を除外できる。

except - リファレンス - Railsドキュメント