PG :: SyntaxError:ERROR:语法错误在或附近" AS"错误Rails 4.1

时间:2014-09-18 19:38:40

标签: ruby-on-rails postgresql activerecord

我刚刚将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

1 个答案:

答案 0 :(得分:7)

rails 4.1中的新语法count(:all)解决了我的问题。