Newby Question about Methods

Hi,

i´m new to Ruby and have some problems when i´m creating new methods for my application. I read different tutorials and understand the structure (okay, i thought i did ;-)).

Now i build my own little application where i have 4 models: the user, book, category and booking. The booking model has among others 2 fields, startdate enddate. I have a list with bookings from a user, where i want show which books he had lend from which category and show the difference between the end and the start-date (not in words, mayby in days or hours). Around this list i have an each do loop. Now i have found different examples to create a method to get the date difference, but i don´t know HOW i have to implent it in my application, WHERE this method has to stand (in the Model or the controller?) and how it has to look in the view.

thanks for your help!

I have a list with bookings from a user, where i want show which books he had lend from which category and show the difference between the end and the start-date (not in words, mayby in days or hours). Around this list i have an each do loop. Now i have found different examples to create a method to get the date difference, but i don´t know HOW i have to implent it in my application, WHERE this method has to stand (in the Model or the controller?) and how it has to look in the view.

Personally, I'd have 2 methods here: a booking_length method on your model (which sounds like it it just needs to compute the difference between those 2 columns) and a view helper (say display_booking_length that calls that method and turns the returned number into a user readable string.

Your view just needs to do

<%= display_booking_length booking %>

fred

Thanks for your help!

The 2 columns in the booking model are end_at and start_at and i need the difference between these two dates in minutes. In the booking model i want to do something like this:

booking.rb   def date_diff       minutes = Booking.new       date2 = Time.end_at       date1 = Time.start_at       difference = date2 - date1       minutes = (difference % 3600) / 60   end

booking.controller ???

I´m aware that this method doesn´t work but have problemes to bring it in the right form. And how does the view helper has to look like?