2015-04-03 70 views
1

我在生產中遇到postgresql問題。我有organizations_controller在postgres中無法工作範圍

def index 
    @organizations = Organization.alphabetically 
end 

,並在我的模型organization.rb

scope :alphabetically, -> { order("title ASC") } 

我想顯示該組織的標題按字母順序排列,在我使用sqlite3發展,一切工作正常,但它不會在生產工作,我在那裏使用postgres。有任何想法嗎?感謝您的提前!

+0

你可以傳遞一個選項哈希代替一個字符串:'order(created_at :: asc)' – Mohamad 2015-04-03 13:31:09

+0

你是什麼意思?我嘗試了,但在'posgres'上這不起作用 – 2015-04-03 13:43:57

+0

既然你已經標記了這個PostgreSQL,那麼顯示你的查詢生成器正在生成的實際SQL可能是一個好主意。 – 2015-04-05 11:46:13

回答

0

使用此代碼:

Model.order('created_at ASC').uniq.pluck :description

首選此鏈接https://github.com/activeadmin/activeadmin/issues/2324瞭解更多詳情。

+0

這不行!也許它用於'activeadmin'? – 2015-04-03 13:46:28

0

做檢查此更深:

Organization.alphabetically.to_sql 

此外,考慮到ASC是默認順序,所以你可以做到以下幾點:

scope :alphabetically, -> { order(:title) }