2010-12-17 2 views
0

다음 쿼리에 order by birthdate desc을 어떻게 추가 할 수 있습니까?레일 2.1.1에서 선택 쿼리로 순서를 추가하는 방법

User have friends 
User have profile 

    now = Date.today 
    end = now + 7.days 

u= User.find(id) 
@somevariable = u.friends.select{|f| 
     date = f.profile.birthdate if f.profile 
     selected = false 
     if date 
if (now.month == date.month) && (date.day >= now.day && date.day <= end_day.day) 
      selected =true 
     elsif (end.month == date.month) && (date.day <= end.day && end_day.month != today.month) 
      selected = true 
     else 
      selected=false 
     end 
     end 
     selected } 

결과는 birthdate으로 주문해야합니다.

+0

코드를 들여 쓰기를 할 수 있습니까? 적절한 코드 삽입을 사용하십시오. –

답변

0

이렇게하는 게으른 방법은 #sort_by을 끝내는 것입니다. 그러나 나는 그렇지 않습니다. 코드를 수정하면 초기 검색 중에 주문할 수 있습니다. 그러나 읽을 수는 없습니다.

관련 문제