我刚刚将rails升级到4.1并收到此错误:
PG::SyntaxError: ERROR: syntax error at or near "AS"
LINE 1: SELECT COUNT(count_column) FROM (SELECT * AS count_column F...
^
: SELECT COUNT(count_column) FROM (SELECT * AS count_column FROM (SELECT thread_id, max(id) as id FROM "messages" WHERE 1=0 AND (thread_id IS NOT NULL) GROUP BY thread_id) last JOIN messages ON messages.id = last.id LIMIT 5 OFFSET 0) subquery_for_count
以下是方法:
- as_myself do
%li#messages-open.icon-btn.email
- message_count = inbox_messages.count.is_a?(Hash) ? inbox_messages.count.values.first : inbox_messages.count
- if(message_count.present? && message_count > 0)
%span= message_count
答案 0 :(得分:7)
rails 4.1中的新语法count(:all)
解决了我的问题。