简体   繁体   中英

Ruby on Rails - SQL Query count

I need to count all the microposts of my image where the status is equal to new .

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

I have tried this line but it doesn't work:

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

Is there a way I can add a condition ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM