Appointment History template page

Ok so I got an Appointments page (index.html.erb)

How would I go about adding an Appointment History page?

  1. adding a history.html.erb and editing my routes?

or

  1. use some kind of get parameter (e.g. /appointments/history) and
    adding it to the appointments controller (eg def history )?

On 15 October 2010 16:50, Leonel . [email protected] wrote:

Ok so I got an Appointments page (index.html.erb)

How would I go about adding an Appointment History page?

  1. adding a history.html.erb and editing my routes?

I presume you mean adding a history controller

or

  1. 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.

Colin

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

Then I go to this URL: http://localhost:3000/appointments/history

I get error…
ActiveRecord::RecordNotFound in AppointmentsController#show
Couldn’t find Appointment with ID=history

But it’s pointing to the show action.

It’s kinda obvious by the error message what the problem is, thing is, I
don’t know how to achieve what I want.

http://guides.rubyonrails.org/routing.html#adding-more-restful-actions

Tried it, same error. On the controller I even tried…

resources :appointments do
get ‘history’ => :history
end
get “appointments/history”

What you wanted to do could be achieved by routing:

http://guides.rubyonrails.org/routing.html#adding-more-restful-actions

HTH

On Sat, Oct 16, 2010 at 5:42 AM, Leonel . [email protected]
wrote:

 @appointments = Appointment.all(:order => 'start', :conditions =>

end
don’t know how to achieve what I want.
.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Erol M. Fornoles
http://erolfornoles.posterous.com
http://github.com/Erol
http://twitter.com/erolfornoles
http://ph.linkedin.com/in/erolfornoles

IMPROVED.

ROUTES
resources :appointments do
collection do
get ‘history’ => ‘appointments#index’
end
end

CONTROLLER
def index
if request.request_uri==history_appointments_path
#past appointments
@appointments = Appointment.all(:order => ‘start’, :conditions =>
[ “start < ?”, Date.today ] )
else
@appointments = Appointment.all(:order => ‘start’, :conditions =>
[ “start >= ?”, Date.today ] )
end

VIEW

<%= link_to 'Appointments History', history_appointments_path %>

Got it, I think when I restarted the server, it didn’t see the changes
or something.

ROUTES
resources :appointments do
collection do
get ‘history’ => ‘appointments#index’
end
end

CONTROLLER
def index
if request.request_uri==’/appointments/history’
#past appointments
@appointments = Appointment.all(:order => ‘start’, :conditions =>
[ “start < ?”, Date.today ] )
else
@appointments = Appointment.all(:order => ‘start’, :conditions =>
[ “start >= ?”, Date.today ] )
end

I just probably need to use a helper for the link in the if statement

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs