This book is for web developers who have a basic, reasonably thorough understanding of the Marionette framework. Ideally, you will have already built one or two web apps with Marionette. If you arent yet comfortable with Marionette, you might want to check out my introductory book or at least study the source code of the ContactManager application (developed throughout the introductory book), as well be building on that web app.
This book will cover bending Backbone.Marionette.js to your will, so that your web apps remain maintainable even as you introduce advanced interaction capabilities, and must deal with sub-optimal situations (such as legacy APIs).
Following Along with Git
This book is a step by step guide to building a complete Marionette.js application. As such, its accompanied by source code in a Git repository hosted at https://github.com/davidsulc/marionette-gentle-introduction.
Throughout the book, as we code our app, well refer to commit references within the git repository like this:
| Git commit with the original application: 317510dc7b0b7854f14462e93a27bd735603d41e |
This will allow you to follow along and see exactly how the code base has changed: you can either look at that particular commit in your local copy of the git repository, or click on the link to see an online display of the code differences.
| Any change in the code will affect all the following commit references, so the links in your version of the book might become desynchronized. If thats the case, make sure you update your copy of the book to get the new links. At any time, you can also see the full list of commits here, which should enable you to locate the commit youre looking for (the commit names match their descriptions in the book). |
Setting up
Well be using a remote API, implemented in Ruby on Rails. Dont worry, you wont need any knowledge of Rails to use it, and will be able to focus entirely on the Marionette portion.
Get the source code for the application, by either:
- downloading the source from here
- using Git to clone the repository:
git
clone
git
:
//github.com/davidsulc/marionette-serious-progression-server.git
Deploying
| The provided Rails application is not recommended for use in production, as several sub-optimal modifications had to be implemented in order to provide a better learning experience for this book. Should you wish to use Rails as your framework of choice in a production application, take a look at Agile Web Development with Rails 4, Rails 4 in Action, or ruby.railstutorial.org/. |
Dont forget that this project will start with an empty database, so you wont see any contacts initially! Youll have to create a few of your own to start with.
Locally
If you want a local development environment, install Rails by following these instructions. Of course, you wont need to create new project, since youll be using the one provided above. You will, however, need to install the requisite packages by executing bundle install
in a console, from your projects root folder.
| The package list includes the pg gem, used for interacting with a PostgreSQL database (as used by Heroku). If you only want to deploy locally, you can either: - make sure you have PostgreSQL installed on your machine;
- comment the line (adding a # at the start) starting with gem pg in the Gemfile file located at the project root (or remove it).
|
| If youre on OS X and Xcode is giving you issues installing the JSON gem, try executing this command first ARCHFLAGS =- Wno - error = unused - command - line - argument - hard - error - in - future gem instal \l json
and then trying to rerun bundle install You can find more on the issue here. |
Youll also need to configure your database schema by running the following command at the prompt (again from the applications root directory):
rake
db
:
migrate
Youll see some text scroll in your console, indicating that the various schema modifications were carried out and youll be ready to start with the Marionette development.
Last step: start the Rails server by navigating to the project folders root in a console, and typing in
rails
server
This will start a development server running locally, and will indicate the URL to use (usually http://localhost:3000
). If you head there, you should see a message indicating that the server is ready for you.
Remotely
If you want a (free) remote production environment, take a look at Heroku (quick start, deploying an application). Note: I dont get anything from Heroku for mentioning their solution. Ive used them in the past and the single-step deployment is simply well-suited to our objectives (i.e. focusing on Marionette, not deployment and systems administration).