範圍測試我有belongs_to :contact
Ruby on Rails的當前用戶
我想在request.rb文件範圍語句來測試,如果接觸是當前用戶的請求表。
scope :myopen, where(:contact_id => current_user.id)
返回: 未定義的局部變量或方法`CURRENT_USER」
應怎樣使用當前用戶ID?
謝謝
範圍測試我有belongs_to :contact
Ruby on Rails的當前用戶
我想在request.rb文件範圍語句來測試,如果接觸是當前用戶的請求表。
scope :myopen, where(:contact_id => current_user.id)
返回: 未定義的局部變量或方法`CURRENT_USER」
應怎樣使用當前用戶ID?
謝謝
你不能這樣做,你也不應該這樣做。在數據庫級別沒有「當前」用戶。
您需要將用戶對象到一個類級別的方法:
def self.open_for_user(user)
where(:contact_id => user.id)
end
當前用戶的ID,但我認爲你需要一個拉姆達範圍。不確定,並且無法從移動瀏覽器中刪除此評論:( –