<file_sep># Hey Orc

A sample Ruby on Rails application that uses Orchestrate.
<file_sep>class LocationsController < ApplicationController

  def index
   @locations = Location.all
  end

  def show
    @location = Location.find params[:id]
    @comments = @location.comments
  end

  def new
    @location = Location.new
  end

  def create
    @location = Location.create! attributes
    redirect_to :action => 'show', :id => @location.id
  end

  def search_results
    query_str = (params[:query_str].blank?) ? '*' : params[:query_str]
    @name = "Search results for '#{query_str}'"
    @locations = Location.search_results(query_str)
  end

  private
    def generate_primary_key
      params[:location][:name].downcase.tr(': ', '_')
    end

    def attributes
      params[:location].merge(:id => generate_primary_key)
    end
end
<file_sep>Rails.application.routes.draw do

  root to: "locations#index"

  get "search_results" => "locations#search_results"

  resources :locations
end
<file_sep>Orchestrate::Rails::Schema.define_collection(
  :name           => 'locations',
  :classname      => 'Location',
  :properties     => [ :Name, :City, :State ],
  :event_types    => [ :comments ]
)

Orchestrate::Rails::Schema.define_event_type(
  :collection => 'locations',
  :event_type => :comments,
  :properties => [ :User, :Comment ]
)
<file_sep>class Location < Orchestrate::Rails::Model

  def comments
    self.events('comments')
  end
end
