Wednesday, November 14, 2012

[Rails] in standby for an annoying problem.

I have a model Reservation with reserved_from and reserve_to
attributes of type date.
I want create a scope of all reservations where Date.today is between
reserved_from and reserved_to.
In the model I've done:

def self.today_reservation
find_each do |res|
if (Date.today).between?(res.reserved_from, res.reserved_to)
return
else
puts "false"
end
end
end
scope :today_reservations, today_reservation

but it doesn't work.
If reserved_from is 2012-11-01 and reserved_to is 2012-11-02 and
Date.today is 2012-11-14 the method above method return an
activerecord relation.
Some advice?
Thank you.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate