sql - Ruby on Rails - SQL 查询计数

标签 sql ruby ruby-on-rails-3 sqlite

我需要统计我的图片状态为的所有微博。

<% for column in @images %>
  <%= column.id %>
  <%= column.microposts.count() %>
<% end %>

我试过这条线,但它不起作用:

<%= column.microposts.count(" WHERE status='new' ") %>

有什么方法可以添加条件吗?

最佳答案

column.microposts.where(:status => 'new').count

关于sql - Ruby on Rails - SQL 查询计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12653434/

相关文章:

ruby - gem 安装 dm-postgres-adapter 构建错误

ruby-on-rails - 将 PG::Result 转换为 Active Record 模型

ruby-on-rails - 使用 CanCan,我如何根据关联/子属性限制能力

mysql - SQL : update table from another grouped table

SQL Server 2005 : Scale of numeric expression changes when adding SUM()

mysql - Select from Different Tables Where 两个子句

ruby-on-rails - 将某些 Rails 对象从暂存转移到 heroku 上的生产数据库

mysql - 来自同一个表的内连接

ruby-on-rails - 在 Rails 3.1 中存储模型特定常量的最佳位置?

ruby-on-rails-3 - 带有命名空间模型的 Rails 自定义验证消息