Skip to content

Instantly share code, notes, and snippets.

@fadhlirahim
Created March 7, 2012 07:23
Show Gist options
  • Save fadhlirahim/1991616 to your computer and use it in GitHub Desktop.
Save fadhlirahim/1991616 to your computer and use it in GitHub Desktop.
rails return json for fullcalendar.js dates displays
# Model
class Meeting < ActiveRecord::Base
scope :date_range, lambda {|*args| where("start_date between ? and ?", args.first, args.last) }
end
#Controller
# fullcalendar.js dates displays
def meeting_dates
start_range = params[:start].present? ? Time.at(params[:start].to_i) : Date.civil(Time.now.year, Time.now.month, 1)
end_range = params[:end].present? ? Time.at(params[:end].to_i) : Date.civil(Time.now.year, Time.now.month, -1)
@meetings = Meeting.date_range(start_range, end_range).by_account(current_account.id)
respond_to do |format|
format.json { render :json => @meetings}
format.html
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment