# Month view

**URL:** <https://www.ruby-forum.com/t/month-view/131159>\
**Category:** Rails\
**Created:** [March 6, 2008, 4:14pm UTC](https://www.ruby-forum.com/t/month-view/131159 "2008-03-06T16:14:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariachi77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@mariachi77](https://www.ruby-forum.com/u/mariachi77)\
**Post date:** [March 6, 2008, 4:14pm UTC](https://www.ruby-forum.com/t/month-view/131159/1 "2008-03-06T16:14:02Z")

</div>

Hey guys need some help, I have a model like this:  
t.integer :company\_id  
t.string :truck  
t.string :trailer  
t.string :driver  
t.string :from  
t.date :load\_on  
t.decimal :price

and I want to be able to see the trips in a month view like on this  
website: [TV Calendar July 2023 - Prime Time TV Schedule & TV Episode Calendar: Track your favourite TV shows](http://www.pogdesign.co.uk/cat/)

I have no idea how to do it, any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![mariachi77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@mariachi77](https://www.ruby-forum.com/u/mariachi77)\
**Post date:** [March 6, 2008, 4:48pm UTC](https://www.ruby-forum.com/t/month-view/131159/2 "2008-03-06T16:48:13Z")

</div>

2008/3/6, Michael P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> and I want to be able to see the trips in a month view like on this  
> website: [http://www.pogdesign.co.uk/cat/](http://www.pogdesign.co.uk/cat/)

See: [http://wiki.rubyonrails.org/rails/pages/UnderstandingViews](http://wiki.rubyonrails.org/rails/pages/UnderstandingViews)  
You probably want to use tables.

HTH,  
Stefan

---

<div class="post-metadata">

**Author:** ![mariachi77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@mariachi77](https://www.ruby-forum.com/u/mariachi77)\
**Post date:** [March 6, 2008, 5:04pm UTC](https://www.ruby-forum.com/t/month-view/131159/3 "2008-03-06T17:04:41Z")

</div>

It’s not about the views it’s the controller I added something like  
this:

`start_of_month = Date.today #create a DateTime object that is at 
the beginning of the month you are displaying
    end_of_month = 31/03/2008 #create a DateTime object that is at the 
end of the month you are displaying
    @trips = Trip.find(:all, :conditions => ["load_on BETWEEN ? AND ?", 
start_of_month, end_of_month]
@trip_days = @trips.group_by { |m| m.load_on.day }`

and then in the view

```auto
@trip_days.sort.each do |day, trips|
       day
       for trip in trips
         trip.truck
       end
```

but this doesn’t really work, and I want it to automatically show the  
current month.

---

<div class="post-metadata">

**Author:** ![mariachi77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@mariachi77](https://www.ruby-forum.com/u/mariachi77)\
**Post date:** [March 6, 2008, 7:26pm UTC](https://www.ruby-forum.com/t/month-view/131159/4 "2008-03-06T19:26:50Z")

</div>

2008/3/6, Michael P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> and then in the view
> 
> ```auto
> @trip_days.sort.each do |day, trips|
> > day
> > for trip in trips
> > trip.truck
> > end
> ```
> 
> but this doesn’t really work, and I want it to automatically show the  
> current month.

What does not work? Do you get an exception? No data on the page?

Assuming your view is rhtml, it should look more like:

```
<html>
   more markup blah, blah, blah
   <% @trip_days.sort.each do |day, trips| %>
     <%= day %>
     <% for trip in trips %>
       <%= trip.truck %>
     <% end %>
   <% end %>
   more markup
</html>

```
