Software Development

Create shiny, handsome dashboards with the Ruby on Rails-based Dashing

Tony Patton shows how to build a quick-and-dirty Ruby on Rails app and then create an impressive dashboard using the Ruby on Rails-based tool Dashing.

railsdashingfigh040114.jpg
A sample dashboard created with Dashing, a Ruby on Rails-based tool.

I have only heard and read good things about Ruby on Rails, but time and work constraints had never provided me with the opportunity to take a closer look at it. This changed on a recent project for creating an operations dashboard with a Ruby on Rails-based tool called Dashing. I needed to dive into Ruby on Rails to take full advantage of the solution.

Why is Ruby on a rail?

Ruby on Rails has two separate parts: the Ruby language itself and the Rails framework for quickly building web applications with Ruby. Ruby is a programming language with uses beyond web applications. It is an interpreted and object-oriented language, thus no compiler -- source code files are decoded and executed when the Ruby interpreter runs. This means you can edit files and make changes on the fly, but I strongly suggest using a source control system like Git.

Ruby must be installed to utilize Rails. Ruby is available for most operating systems via the RubyInstaller.org site. After installing Ruby, you need to install the Ruby Development Kit, which is available on the download section of RubyInstaller.org.

A package manager called RubyGems is included with Ruby beginning with version 1.9 (it was a separate installation in previous versions). Self-contained Ruby programs or libraries are called gems. One such gem is Rails, so the command line can be used to install it once Ruby is set up (gem install Rails).

Another highly recommended gem is Bundler, which does the dirty work of maintaining a consistent environment for applications by tracking dependencies. A quick browse of freely available gems shows there is something for almost everything. Finally, you will need a database for backend data storage in your Ruby on Rails application; MySQL along with SQLite are popular options.

A quick and dirty application

Once the Ruby on Rails environment is set up, you can start building applications with a few commands. The rails command is used to create new Ruby on Rails-based applications.

Figure A shows the creation of a new Ruby on Rails site called Techrepublic. Figure B shows the newly created application's directory structure. The scaffolding feature of Rails can be used to quickly build frontend interfaces to backend data. Figure C shows the generate scaffold command used to create an interface for our backend data that has two columns: address and comments. Figure D shows the Rails server started for working with our locally set up development environment. Figure E displays the form generated to interact with our data. Figure F displays the results of the scaffold command displayed in Chrome.

Figure A

railsdashingfiga040114.jpg

Creating a new Ruby on Rails application at the command line.

Figure B

railsdashingfigb040114.jpg

The directory structure for the newly created application.

Figure C

railsdashingfigc040114.jpg

The generate scaffold command is used to create an interface for our backend data.

Figure D

railsdashingfigd040114.jpg

My local Rails server is started to work with the application.

Figure E

railsdashingfige040114.jpg

The default page displayed on my local Rails server started in Figure D.

Figure F

railsdashingfigf040114.jpg

The results of the scaffold command displayed in Chrome browser.

This quick rundown of Ruby on Rails from installation to simple application by no means covers everything; fortunately, there is a lot of information about Ruby on Rails that's freely available on the web. A great site for everything Ruby on Rails related is RailsGuides -- specifically, the getting started page gives you play-by-play information on getting up and running. The screencasts are a good way to learn as well, and do not discount the official documentation. There are an overwhelming number of gems available as well; check out RubyGems.org for more information.

Create great interfaces with Dashing

Dashing provides everything you need to create dynamic dashboard interfaces, including a set of premade widgets to easily present data in a graphical format (check out one of the demos). You can customize these widgets via web standards (HTML, SCSS, and CoffeeScript) and develop your own if there is nothing that meets your needs.

Dashing is installed by way of the previously discussed gem feature (gem install dashing). Once installed, a new Dashing-based application is created using Rails syntax (dashing new <project name>). The result is a directory within all necessary components (type dashing start to see the site in action). Figure G shows it started on my development machine, while Figure H displays the base sample created with the new project and opened in Chrome.

Figure G

railsdashingfigg040114.jpg

Dashing installed and started.

Figure H

railsdashingfigh040114.jpg

Sample dashboard created with Dashing.

The power of Dashing is offered by the Rails framework as well as the simple way to customize it. Each widget (i.e., one colored block or section of the screen in Figure H) is contained in an HTML DIV element with attributes for connecting to data and LI elements for layout. You'll find useful information in the example section of the Dashing site.

Only the beginning

When I first started out as a developer I remember learning new languages and technologies at breakneck speed, but these days the number of development options is overwhelming, and each language requires your full attention to stay up to date -- or maybe I'm just getting old. While the learning curve for Ruby and the Rails framework is steep, the wealth of web resources about it makes it easy to get going.

The Dashing solution provides a great vehicle for building dashboards, and I plan to provide additional coverage in future articles.

Also see

About

Tony Patton has worn many hats over his 15+ years in the IT industry while witnessing many technologies come and go. He currently focuses on .NET and Web Development while trying to grasp the many facets of supporting such technologies in a productio...

0 comments

Editor's Picks