This is the example Rails application that is used for a refactoring blog post series published on 8thlight.com:
- Getting Rails on Track - Part 1: Models
- Getting Rails on Track - Part 2: Views
- Getting Rails on Track - Part 3: Controllers
The three different branches (part-1-models
, part-2-views
, part-3-controllers
) build upon each other and show step by step – or commit by commit – how to separate the specific concerns discussed in the corresponding blog posts.
Traditionally Rails follows an MVC approach to structure our application. Models represent database tables—for the most part. Views are the HTML pages we interact with through the browser. Controllers mediate between actions triggered via the view and corresponding modifications on a model (think submitting a form to update a database record).
That's a great and straight forward approach for small applications. But having only three “buckets” to put the different parts of our application into is not enough anymore once our application starts growing.
In the blog post series we're going hands-on through the steps that can help transform the design of a default Rails application into one with clearer responsibilities and that is easier to test.
After cloning the repository make sure to bundle all dependencies.
bundle install
Then set up the inital database structure and content.
bundle exec rake db:setup
Once that's done start up the application.
bundle exec rails s
The application should be available at localhost:3000 now.
- Ruby 2.3.1
- Rails 4.2.1
- SQLite
Source of the movie description data used for seeds is from imdb.com.