module Orchestrate::Rails::Tutorial::BuildTheApp

Building the rails application

Setting up the rails routing

Add the following lines to <rails-root>/config/routes.rb

root to: "films#index"
resources :films

Setting up the schema for the films collection

Since collection data cannot be expected to conform to orchestrate-rails convention, a schema must exist to ensure that collection names and properties are correctly mapped.

Below is the schema definition for the films collection.

Create the file <rails-root>/db/schema.rb as shown:

Orchestrate::Rails::Schema.define_collection(
  :name           => 'films',
  :classname      => 'Film',
  :properties     => [ :Title, :Year, :Rated, :Released,
                       :Runtime, :Genre, :Director, :Writer,
                       :Actors, :Plot, :Poster, :imdbRating,
                       :imdbVotes, :imdbID, :Type, :Response ],
  :event_types    => [ :comments ],
  :graphs         => [ :sequel ],
)

Orchestrate::Rails::Schema.define_event_type(
  :collection => 'films',
  :event_type => :comments,
  :properties => [ :User, :Comment ]
)

Orchestrate::Rails::Schema.define_graph(
  :collection    => 'films',
  :relation_kind => :sequel,
  :to_collection => 'films',
)

Add the following line to <rails-root>/config/application.rb

Orchestrate::Rails::Schema.load "./db/schema.rb"

Creating the Film model.

Create <rails-root>/app/models/film.rb as shown:

class Film < Orchestrate::Rails::Model
end

Yep, that's it. Here are the method definitions for the model class.

Creating the films controller.

Let's start by creating an index action to provide a list of the collection's contents.

Create <rails-root>/app/controllers/films_controller.rb, as shown:

class FilmsController < ApplicationController

  def index
   @films = Film.all
  end
end

Creating the view for the index action.

Let's add an index view so we can see what we've accomplished so far.

Important: HAML uses indentation as part of its syntax, so be mindful of that when when cutting-and-pasting the HAML code samples presented throughout this tutorial.

Create <rails-root>/app/views/films/index.html.haml as shown:

%ul.films.list-group
 %li.list-group-item
  - title = "Films - Orchestrate.io Example Application"
  = render partial: 'films/film_list', locals: { title: title, films: @films }

Now we'll add the partial view that displays a list of films.

Create <rails-root>/app/views/films/_film_list.html.haml as shown:

%h3.list-group-item-heading= title
%ul.list-group
 %li.list-group-item
  .row.list-group-item-heading
   .col-md-4= "TITLE"
   .col-md-1= "YEAR"
   .col-md-1= "RATED"
   .col-md-4= "GENRE"
   .col-md-2= "COLLECTION"
  - films.sort_by { |f| f.year.to_i }.each do |film|
   .row
    .col-md-4= link_to "#{film.title}", film_url(film.id)
    .col-md-1= film.year
    .col-md-1= film.rated
    .col-md-4= film.genre
    .col-md-2= film.orchestrate_collection_name

Note: The links in this view are broken because the show action has not yet been implemented.

Ready to roll

Start the rails server

$ rails s

Point the browser to localhost:3000.

Next

Adding the show action