Pull full date from group_by

Hello there,

I started with to_set.classify and have the find function grouping by
day. I then did a group_by function to the same effect both in the
model and the view.

They both work wonderfully except I need to pull the full date from it
not just the number of the day.

controller

@groups = Lineup.find(:all, :conditions => search_conditions, :limit
=> 400, :include => [{:event => :venue}, {:artist
=> :genre}, :artist]).to_set.classify {|lineup|
lineup.event.event_time.day}.sort

In the view I have two loops set to run through the day then the
lineups.

strftime will not work since it is a fix num but I need the month of
the day and the name of the day.

Any ideas? Thanks for your help!

Best,

Jackson

I do have the same question, did you find any answer ?

thanks

def day
self.event.event_time.strftime("%y%j%d%B%A")
end

This will sort by year to account for January then the day number.

I have it pulling using a method that I created in the model.

def day
self.event.event_time.strftime("%B%d%A")
end

That spits out the string that I require then I parse it with reg ex
and match.

In the view I have:

<% @groups.group_by(&:day).each do |day, lineups| %>

Now the problem is sorting. If I sort in the view, I’m sorting by
strings.

In the controller:

@groups = Lineup.find(:all, :conditions => search_conditions, :limit
=> 400, :include => [{:event => :venue}, {:artist
=> :genre}, :artist]).sort_by{|e| e.event.event_time}

I can sort by time but it only sorts the individual lineups, the group
by day seems to be unaffected.

Dates are fun…

Can anyone provide some direction?

Thanks,

Jackson

Yeah,

Went well!

controller::

@groups = Lineup.find(:all, :conditions => search_conditions, :limit
=> 400, :include => [{:event => :venue}, {:artist
=> :genre}, :artist]).sort_by{|e| e.event.event_time}

model::

def day
self.event.event_time.strftime(“%y%j%d%B%A”)
end

view::

<% @groups.group_by(&:day).sort.each do |day, lineups| %>

<%= day.match(‘((?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|
May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:t|ember)?|Oct(?:ober)?|
Nov(?:ember)?|Dec(?:ember)?))’).to_s.upcase %>

<%= this.event.event_time.strftime(“%I” + “:” + “%M%p”) %>

<% end %>

The second repeat is hobo dryml but it should make sense.

The controller call sorts every return. The model’s definition was
key. I had to find all by day using the strftime function but needed
more info than just the day number. I put month, day, day full name.
That was tough to sort because you trade in the datetime class for a
string, I added year then day of the year so the records would come
back in order. The view I pulled the substrings using regex matches.
(http://txt2re.com/)

I hope this helps. Let me know if you have any questions, I’ll see
what I can do.

Best,

Jackson