One of the great advancements of Rails 3 brought to the table was enough
modularity to let you build custom Rails stacks tuned to specific
needs. Out of the box Rails is tuned to be as inclusive as possible,
bringing you as many features as it possibly can. It’s modular enough
you
can remove what you want if you don’t need it, but by default ships with
everything on.
This inclusiveness lead to a backlash of minimalist frameworks, most
notably Sinatra. Sinatra tried to provide as little as possible while
still
being useful, and at the same time removed much of the Rails ceremony
from
the DSL it used for rendering responses.
Thanks to Rails 3, the framework is now modular enough you can boot a
barebones version of it from a single file:
https://gist.github.com/1942658
Lightrail ships a Rails 3 barebones stack, but with some added niceties
for
apps that provide JSON APIs:
https://github.com/lightness/lightrail
It’s minimalist Rails 3 with enough Sinatraisms baked in I hope it can
win
over some of those people who think Rails is too bloated and use Sinatra
instead. That’s not to say Sinatra is bad, but I have seen apps built on
Sintra which have outgrown it, and for them, I think a Rails-based stack
would be a better choice.
For those of you who hated Rails 3’s stack traces, Lightrail ships with
minimal middleware and is tuned to eliminate many of the frustrations
which
give the impression Rails is a big bloated framework.
Lightrail is originally derived from the Rails 3 stack used for
applications with client-heavy SproutCore front-ends at Strobe (
http://strobecorp.com). Its principal authors are Jos Valim and Carl
Lerche.
–
Install the lightrail gem:
gem install lightrail
Like Rails, installing the lightrail gem will install a command line
utility called ‘lightrail’. This command is in fact identical to the
‘rails’ command, but tweaked for Lightrail defaults instead of Rails
defaults.
You can use ‘lightrail’ to create a new application skeleton just like
Rails:
lightrail new myapp
The skeleton application that Lightrail generates is identical to a
standard Rails application, with only these changes:
- Gemfile pulls in lightrail instead of rails
- application.rb pulls in lightrail instead of rails
- ApplicationController descends from
Lightrail::ActionController::Metal
instead of ActionController::Base. ActionView is not used or
installed.
Once you’ve created your application, run:
lightrail server
to launch a web server in the development environment (just like Rails!)
You can convert an existing Rails 3 application to a Lightrail
application
by retrofitting the changes mentioned above.