bogdanrada
8/18/2015 - 3:07 PM

Simple Rails app compatible with DHTMLX Scheduler http://www.dhtmlx.com/docs/products/dhtmlxScheduler/index.shtml

Simple Rails app compatible with DHTMLX Scheduler http://www.dhtmlx.com/docs/products/dhtmlxScheduler/index.shtml

rails new scheduler
cd scheduler
rails generate scaffold Events text:string details:text start_date:datetime end_date:datetime _timed:boolean
rake db:migrate
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
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