All of my stat tables house data that is compiled weekly. I know how to add a date range selector to the table but I''m not sure how I can restrict the selector to show specific weeks only unless I use a symbolic type of selector. For instance: Suppose there are 13 weeks in a season. Data is added each of the 13 weeks. A person wants to view just the data from week 1. In my table week 1 would have been between the date ranges of say Aug 31 - Sep 6. Should I just use a symbolic selector instead with options for say: Week 1 Week 2 Week 3... And then provide a case for when that week is selected it is sent over to a defined named_scope for that particular week? I''m just thinking about possibilities and what might be a better way of doing things. Thanks. -- Posted via http://www.ruby-forum.com/.
I was playing around with distinct and tried the following: <%= collection_select(:rushing_offense, :compiled_on, RushingOffense.find(:all, :select => ''DISTINCT compiled_on''), :id, :compiled_on, {:prompt => true}) %> With my current week''s data for instance there are 120 timestamps. Using the above, it pulled 2 options only (which is not bad but also not good). The difference was within a second apart: Please Select-- 2009-06-28 12:08:40 UTC 2009-06-28 12:08:41 UTC Probably because it took a second to load the batch. I would rather work with something like this but tailor it some more.. I''ll see what I can work out but if anyone has better ideas please let me know. thanks. -- Posted via http://www.ruby-forum.com/.
One thing - if you''re only ever going to be interested in the date, I''d recommend changing the compiled_on field to a date, rather than a datetime. That will eliminate the "off by 1 second" thing you''re seeing. --Matt Jones On Jun 28, 9:02 am, "Älphä Blüë" <rails-mailing-l...-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt> wrote:> I was playing around with distinct and tried the following: > > <%= collection_select(:rushing_offense, :compiled_on, > RushingOffense.find(:all, :select => ''DISTINCT compiled_on''), :id, > :compiled_on, {:prompt => true}) %> > > With my current week''s data for instance there are 120 timestamps. > Using the above, it pulled 2 options only (which is not bad but also not > good). The difference was within a second apart: > > Please Select-- > 2009-06-28 12:08:40 UTC > 2009-06-28 12:08:41 UTC > > Probably because it took a second to load the batch. I would rather > work with something like this but tailor it some more.. > > I''ll see what I can work out but if anyone has better ideas please let > me know. > > thanks. > > -- > Posted viahttp://www.ruby-forum.com/.
Matt, good call there mate. I created some constants for each week start and end: WEEK_ONE_START = "2009-06-21" WEEK_ONE_END = "2009-06-27" And then defined that in a per search scope: named_scope :compiled_week_one, lambda { { :conditions => [''compiled_on> ? and compiled_on < ?'', WEEK_TWO_START, WEEK_TWO_END] } }And can do that for each of the weeks of the season (13 in total). I also have a default scope using Time.now.beginning_of_week and Time.now_end_of_week for current records but the form search allows the new scopes and all works well. Many thanks. -- Posted via http://www.ruby-forum.com/.
Älphä Blüë wrote:> And then defined that in a per search scope: > > named_scope :compiled_week_one, lambda { { :conditions => [''compiled_on >> ? and compiled_on < ?'', WEEK_TWO_START, WEEK_TWO_END] } } >Actually reads WEEK_ONE_START and WEEK_ONE_END.. -- Posted via http://www.ruby-forum.com/.