How to add conditon in select method

A

Arun Kumar

Hi all,

How to add the condition for "order by birthdate desc" in the following

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 }

The above query is working fine but the order is displaying based on
alphabet,
But i need to show by soonest date (birthdate)
How to achieve this by using order by or any other method ?

Thanks in advance,
Jak
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,365
Latest member
BurtonMeec

Latest Threads

Top