Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Example Application

timClicks edited this page · 2 revisions

Here’s the code necessary to write a very simple CB app. Let’s suppose we have a database of library books, and want to write an application for viewing them.

First, we create a new Chicago Boss project. Under the Chicago Boss directory:

$ make app PROJECT=simple

This creates the directory simple on the same level as the Chicago Boss installation.

Next we define a library_book model. Under the simple directory:

/simple/src/model/library_book.erl:

-module(library_book, [Id, Title, AuthorName]).
-compile(export_all).

Next we define a controller for pulling records from the database. We prefix the filename of our controller with the name of our project.

/simple/src/controller/simple_library_book_controller.erl:

-module(simple_library_book_controller, [Req]).
-compile(export_all).

list('GET', []) ->
    LibraryBooks = boss_db:find(library_book, []),
    {ok, [{books, LibraryBooks}]}.

Finally we make a template file that puts all of the data into a pretty table.

/simple/src/view/library_book/list.html:

<table>
<tr><td>Title</td><td>Author</td></tr>
{% for book in books %}
<tr><td>{{ book.title }}</td>
    <td>{{ book.author_name }}</td>
</tr>
{% endfor %}
</table>

And that’s it! Visiting http://localhost:8001/library_book/list will show us all the library books in the database.

Further Tutorials

This is the most basic of introductions for ChicagoBoss, which doesn’t explain many of the unique features that make it such a great way to build web applications. The community has been developing

  • An Evening with ChicagoBoss, which explains the fundamentals of ChicagoBoss and details how to use features such as writing advanced database queries, sending and receiving email, pushing data to multiple clients in real-time with COMET and more.
Something went wrong with that request. Please try again.