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
It's not about the views it's the controller I added something like
this:
[code]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 }[/code]
and then in the view
[code]
@trip_days.sort.each do |day, trips|
day
for trip in trips
trip.truck
end
[/code]
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>