I have an object that holds the date in the form of “Tue Jul 08
14:18:00-0700 2008” and I want to only display the time in the format
of 6:00-8:00 or just 6:00. The controller looks like this:
def show
@events = Event.find(:all, :conditions => [‘date between ?
and ?’, @date.strftime("%Y-%m") + ‘-01’,
@date.next_month.strftime("%Y-%m") + ‘-01’])
end
I am thinking that I should write a function in the model that changes
the format of this current object to what I want. Something like
def to_s
#some code to change the format
end
and then append this function on the end of the event call like so:
def show
@events = Event.find(:all, :conditions => [‘date between ?
and ?’, @date.strftime("%Y-%m") + ‘-01’,
@date.next_month.strftime("%Y-%m") + ‘-01’]).to_s
end
but I have no idea if this is the right approach or what code to use
in the to_s function. Any help is greatly appreciated!