0

我正在尝试获取 Rails 中“流派”列中的唯一值。注释掉的部分适用于 localhost 但在生产中我得到一个 PG Error: ActiveRecord::StatementInvalid (PGError: ERROR: for SELECT DISTINCT, ORDER BY 表达式必须出现在选择列表中。我找到了这个但不太确定如何应用它适用于我的情况,因为我正在寻找特定列中的唯一值。有什么建议吗?

    @iosapps = Iosapp.where(:user_id => me.id, :payment => 'free', :updated_at => days_ago..present ).order('updated_at DESC')
    @categories = Iosapp.order('updated_at DESC')
.where(:user_id => me.id)
.where(:payment => 'free')
.where(:updated_at => days_ago..present)
.select("distinct genre")

视图中的错误:

2013-05-16T03:32:05.772029+00:00 app[web.2]:     51:             Category:
2013-05-16T03:32:05.772029+00:00 app[web.2]:     52:             <select id = 'category'>
2013-05-16T03:32:05.772029+00:00 app[web.2]:     53:                 <option value = "All">All</option>
2013-05-16T03:32:05.772029+00:00 app[web.2]:     54:                 <% @categories.each do |genre| %>
2013-05-16T03:32:05.772029+00:00 app[web.2]:     55:                     <option value = "<%= genre.genre %>"><%= genre.genre %></option>
2013-05-16T03:32:05.772318+00:00 app[web.2]:     56:                 <% end %>
2013-05-16T03:32:05.772318+00:00 app[web.2]:     57:             </select>
2013-05-16T03:32:05.772318+00:00 app[web.2]:   app/views/iosapps/test.html.erb:54:in `_app_views_iosapps_test_html_erb__2525281577349110042_49052520'
4

1 回答 1

0

也许试试

Iosapp.order('updated_at DESC')
  .where(:user_id => me.id)
  .where(:payment => 'free')
  .where(:updated_at => days_ago..present)
  .select("distinct genre")

我还建议针对您在生产中使用的同一个数据库进行开发

于 2013-05-16T03:05:55.350 回答