How would I go about adding an Appointment History page?
adding a history.html.erb and editing my routes?
I presume you mean adding a history controller
or
use some kind of get parameter (e.g. /appointments/history) and
adding it to the appointments controller (eg def history )?
Either is ok, do it whichever way you think is most appropriate. One
thing to consider is what the views will be like. If the history is
very like your index view then personally I would use a parameter on
the appointments controller that just causes the appropriate records
to be selected. If you think of the history view as being completely
different then do it with it’s own controller.
Either way make sure you write your tests first so that if you decide
later that you prefer the other way then you can be confident that you
have re-factored the code correctly when all the tests pass.
If the history is
very like your index view then personally I would use a parameter on
the appointments controller that just causes the appropriate records
to be selected. If you think of the history view as being completely
different then do it with it’s own controller.
This is what I tried on the APPOINTMENTS_CONTROLLER
def index(display=‘index’)
unless display==‘history’ #past appointments @appointments = Appointment.all(:order => ‘start’, :conditions =>
[ “start < ?”, Date.today ] )
else @appointments = Appointment.all(:order => ‘start’, :conditions =>
[ “start >= ?”, Date.today ] )
appointments = Appointment.all(:order => ‘start’, :conditions => [
“start >= ?”, Date.today ] )
appointments.group_by do |appointment|
appointment.start.strftime("%Y%m%d")
end
end