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 2) use some kind of get parameter (e.g. /appointments/history) and adding it to the appointments controller (eg def history )? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 15 October 2010 16:50, Leonel *.* <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 > > 2) 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> 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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 *.* <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > 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. > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> http://guides.rubyonrails.org/routing.html#adding-more-restful-actionsTried it, same error. On the controller I even tried... resources :appointments do get ''history'' => :history end get "appointments/history" -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 <p><%= link_to ''Appointments History'', history_appointments_path %></p> -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.