0

I'm an amateur programmer working on a ruby on rails application. Up until now, everything has been running smoothly, but now I'm running into a problem. Every time I try to access my 'appointment' model, the server gets stuck and fails to load a page. Here is the index of my controller:

class AppointmentsController < ApplicationController
load_and_authorize_resource
before_filter :get_appointments, :only => :index
def index
    @appointments = Appointment.all
    @months = ["January","February","March","April","May","June","July","August", "September", "October", "November", "December"]
    @appointments = @appointments.select {|appointment| appointment.seller_id == current_user.id }
    @appointments = @appointments.select {|appointment| appointment.completed == false }
    @appointments.sort! { |a,b| a.date_time <=> b.date_time }
end

I don't think the issue is with the view, because I could comment this code out, and then the server would load the page. Here's the model

class Appointment < ActiveRecord::Base
  attr_accessible :buyer_id, :item_id, :seller_id, :location, :date_time
  belongs_to :item

end

Any idea what the issue could be? Help please! Thanks!

Rohan

BonesVI
  • 3
  • 2
  • It's very hard to tell what's wrong based on what you've given. How do you know which line the server is getting stuck on? Do you have an error message? how many appointments are in the database? (ie is it just being super slow and timing out trying to fetch them)? – Taryn East Nov 14 '12 at 04:05
  • maybe problem with `@appointments.sort! { |a,b| a.date_time <=> b.date_time }`, try change it to: `@appointments.sort! { |a,b| b.date_time <=> a.date_time }` – Thanh Nov 14 '12 at 05:26
  • there is no error message, and there are only two appointments. I have commented out the lines individually to narrow down which causes the server to "freeze", and the @appointments = Appointment.all is the only one that keeps the MVC from responding. i tried the order, it does not change the result – BonesVI Nov 14 '12 at 23:05

1 Answers1

0

well this is awkward.. there was a problem with the view page. It was stuck in an infinite loop. Problem solved, thanks for your help anyway!

BonesVI
  • 3
  • 2