Your immediate problem is that you are creating invalid SQL for PostgreSQL:
SELECT category FROM "microposts" GROUP BY category ORDER BY microposts.created_at DESC
Your ORDER BY does not match the rest of your request. You cannot use a column in a grouped query, if this column is also not grouped, or if the column is displayed in an aggregate function, this means an error message. The reason is that PostgreSQL will not know which row created_at use when a group of rows is combined into a GROUP BY clause; some databases will simply select a row on their own, PostgreSQL prefers to be strict and wants you to eliminate the ambiguity.
Try to specify the order yourself:
@categories = Micropost.select("category").group("category").order("category")
Another option is to use DISTINCT instead of GROUP BY to avoid duplication:
@categories = Micropost.select('DISTINCT(category)')
By the way, you really should not do this thing in the view, you can transfer it to your controller.
Your real problem is that you are developing on top of one database when deploying to another. I would recommend switching your development environment to PostgreSQL 8.3 (if you are deploying to a shared Heroku database) or PostgreSQL 9.0 (if you are deploying to a dedicated database).
source share