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
I have no idea how to do it, any help would be greatly appreciated.
2008/3/6, Michael P. [email protected]:
and I want to be able to see the trips in a month view like on this
website: http://www.pogdesign.co.uk/cat/
See: http://wiki.rubyonrails.org/rails/pages/UnderstandingViews
You probably want to use tables.
HTH,
Stefan
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
@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.
2008/3/6, Michael P. [email protected]:
and then in the view
@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>