Login

Ruby on Rails

A web application framework.

Leveraging Ruby on Rails

This article is part of a series. The prior article "Leveraging Ruby on Rails and ClojureScript." detailed the project business and data requirements.
In this article, I'll detail the server implementation using Ruby on Rails, Version 4 (ROR) and SQLite (database server).

Note! Full source on my GitHub repository.

Customizing and Optimizing the Database Schema

ROR provides a database abstraction layer. One of the purposes of a database abstraction layer is provide a single interface for a diverse set of database engines. However, database engines tend to vary. Each database server and version may have unique features. Thus, ROR's database abstraction layer has limits as to what if can do. ROR's database abstraction layer provides a great foundation. The developer has the option to customize and extend that foundation. I'll demonstrate how to customize the schema instructions generated by ROR.

One of the features of ROR is boiler plate code generation. For the application database, ROR has an option to define database schemas and validations. ROR also has an option to store changes to the database schema. Either defining or changing a database schema is referred to as "Migration" in ROR terminology.

For this application's requirements, we'll use the "Migration" files generated by ROR. However, we'll customize the contents of the "Migration" files to meet or detailed requirements. In other words, we will edit the "Migration" files generated by ROR.

Unique Records

One of our detailed requirements is, we want the database to prevent duplicate records. For example, we don't want to have two authors with the name, "Mark Twain". We could set the application to enforce that rule. However, it's both better performance and better architecture, to set those rules in the database schema itself.

Note! We are using ROR's default database engine SQLite. You must verify your SQLite installation is built with foreign key operation support.

For reference as to why we setting the unique rules in the database schema, note the recommendation in the ROR Guide. Section 1.1 Why Use Validations:

" it may be a good idea to use some constraints at the database level. Additionally, database-level validations can safely handle some things (such as uniqueness in heavily-used tables) that can be difficult to implement otherwise."

Leveraging Ruby on Rails and ClojureScript.

Our upcoming sample project focuses on application frameworks and compilers.

Ruby on Rails (ROR) is an application framework written in Ruby.

ClojureScript is a compiler which emits (generates) JavaScript. The ClojureScript compiler is written in Clojure.

Our project will focus on a couple of customizations.

  1. We'll define database integrity rules in the database server (versus the application code).
  2. We'll verify our JavaScript client code, marks nodes, removed from the document, as available for deletion. In other words, we will verify that after we remove an html element from the document, it's underlying object is empty. We will verify the web browser's garbage collector removes the nodes from memory.

As with projects other projects in this series, this project is primarily a learning device. We will build a useful application. However, the main benefit is, to learn technology.

Business Requirements

One of my hobbies is visiting libraries, used book stores, and reading. I want to carry a list of books, authors and categories (E.G. science fiction) with me on my mobile phone. I'd also like to refer to book reviews. Many folks who work in libraries or book stores are great sources for book and author recommendations. Communicating your prior reviews helps folks recommend new books and authors.

Application Architecture

Server will run on a Local Area Network (LAN). That means, access is provided by my LAN. We won't implement application layer authentication and authorization for the initial release.

Our application provides two user interfaces (UI and user experience (UX)).

  1. Full size web browser. Supports create, report, update, and delete (CRUD).
  2. Mobile web browser. Supports reports.
Syndicate content