0

I am trying to get the unique values in the column 'genre' in Rails. The commented out section works on localhost but in production I get a PG Error: ActiveRecord::StatementInvalid (PGError: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list . I found this but am not quite sure on how to apply it to my case as I'm looking for unique values in a specific column. Any advice?

    @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")

Error in the view:

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'
Community
  • 1
  • 1
sharataka
  • 5,014
  • 20
  • 65
  • 125

1 Answers1

0

Maybe try

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

Also i reccomend developing against the same db you are using in production

house9
  • 20,359
  • 8
  • 55
  • 61
  • I don't get an error in the controller anymore but I do get one in the view, that I have included above. I also changed it so production and development are both on PG. I'm still finding that development is able to load the page without error while production isn't. – sharataka May 16 '13 at 03:36