I am trying to solve my heroku problem which it seems to have problem of
We’re sorry, but something went wrong.
We’ve been notified about this issue and we’ll take a look at it shortly.
Is there any mistake I have and how to overcome it?
How can I interpret these Heroku logs?
ActionView::Template::Error (PGError: ERROR: column "microposts.created_at" must appear in the GROUP BY clause or be used in an aggregate function
2011-11-14T17:33:07+00:00 app[web.1]: : SELECT category FROM "microposts" GROUP BY category ORDER BY microposts.created_at DESC):
2011-11-14T17:33:07+00:00 app[web.1]: 2: <% @categories= Micropost.select("category").group("category")%>
2011-11-14T17:33:07+00:00 app[web.1]: 3: <% unless @categories.nil? %>
2011-11-14T17:33:07+00:00 app[web.1]: 4:
2011-11-14T17:33:07+00:00 app[web.1]: 5: <ul><% @categories.each do |category| %>
2011-11-14T17:33:07+00:00 app[web.1]: 6: <li><%= link_to category.category, :controller =>"microposts", :category => category.category, :method => 'category_list' %></li>
2011-11-14T17:33:07+00:00 app[web.1]: 7: <% end %>
2011-11-14T17:33:07+00:00 app[web.1]: 8: </ul>
micropost model (New added)
class Micropost < ActiveRecord::Base
belongs_to :users
default_scope :order => 'microposts.created_at DESC'
attr_accessible :title,:content,:category
validates :user_id, :presence => true
validates :title, :presence => true,
:length => {:maximum =>500}
validates :content, :presence => true,
:length => {:maximum =>3000}
validates :category, :presence => true
end
Your immediate problem is that you’re producing invalid SQL for PostgreSQL:
Your ORDER BY doesn’t match the rest of your query. You can’t use a column in a grouped query unless that column is also grouped or if the column appears in an aggregate function, that’s what the error message means. The reason is that PostgreSQL won’t know which row’s
created_atto use when a group of rows are combined by the GROUP BY clause; some databases will just silently pick a row on their own, PostgreSQL prefers to be strict and wants you to remove the ambiguity yourself.Try specifying the order yourself:
Another option is to use DISTINCT instead of GROUP BY to avoid duplicates:
BTW, you really shouldn’t be doing that sort thing in a view, you might want to move that to your controller.
Your real problem is that you’re developing on top of one database while deploying on another. I’d recommend that you switch your development environment to PostgreSQL 8.3 (if you’re deploying to a Heroku shared database) or PostgreSQL 9.0 (if you’re deploying to a dedicated database).