Skip to content

Instantly share code, notes, and snippets.

@AstDerek
Created January 8, 2013 03:58
Show Gist options
  • Save AstDerek/4481038 to your computer and use it in GitHub Desktop.
Save AstDerek/4481038 to your computer and use it in GitHub Desktop.
Simple Rails app compatible with DHTMLX Scheduler http://www.dhtmlx.com/docs/products/dhtmlxScheduler/index.shtml
class Event < ActiveRecord::Base
attr_accessible :_timed, :details, :end_date, :start_date, :text
# From http://www.dhtmlx.com/docs/products/dhtmlxScheduler/xml/events.xml
def to_xml (options = {})
options[:indent] ||= 2
xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
xml.instruct! unless options[:skip_instruct]
xml.event(:id => id, :timed => _timed) do
xml.text text
xml.details details
xml.start_date start_date
xml.end_date end_date
end
end
end
class EventsController < ApplicationController
# GET /events
# GET /events.json
def index
@events = Event.all
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @events }
format.xml { render :xml => @events.to_xml(:root => "data") }
# From http://www.dhtmlx.com/docs/products/dhtmlxScheduler/xml/events.xml
end
end
# No other methods require XML by the moment
# GET /events/1
# GET /events/1.json
def show
@event = Event.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @event }
end
end
# GET /events/new
# GET /events/new.json
def new
@event = Event.new
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @event }
end
end
# GET /events/1/edit
def edit
@event = Event.find(params[:id])
end
# POST /events
# POST /events.json
def create
@event = Event.new(params[:event])
respond_to do |format|
if @event.save
format.html { redirect_to @event, :notice => 'Event was successfully created.' }
format.json { render :json => @event, :status => :created, :location => @event }
else
format.html { render :action => "new" }
format.json { render :json => @event.errors, :status => :unprocessable_entity }
end
end
end
# PUT /events/1
# PUT /events/1.json
def update
@event = Event.find(params[:id])
respond_to do |format|
if @event.update_attributes(params[:event])
format.html { redirect_to @event, :notice => 'Event was successfully updated.' }
format.json { head :no_content }
else
format.html { render :action => "edit" }
format.json { render :json => @event.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /events/1
# DELETE /events/1.json
def destroy
@event = Event.find(params[:id])
@event.destroy
respond_to do |format|
format.html { redirect_to events_url }
format.json { head :no_content }
end
end
end
rails new scheduler
cd scheduler
rails generate scaffold Events text:string details:text start_date:datetime end_date:datetime _timed:boolean
rake db:migrate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment