My short rant on MVC

If you haven't discovered it already, rails is what is known as "opinionated software". What this means is that the rails authors made decisions on what was good for them, as well as what is good for you, and you have little if any choice about buying into their decisions if you want to use rails.

MVC is short for Model - View - Controller and is a scheme for designing user interfaces. Under MVC you partition your code into these three divisions. This is supposed to be a good thing, and perhaps it is, but I have not seen convincing arguments. I have seen a lot of very good user interfaces designed without strict adherence to MVC. However, Rails is very aggressive about forcing it on you, so you have essentially no choice about doing things this way.

Dealing with the rails MVC setup

Once you start thinking MVC (which you may notice I am not addressing here), you are faced with the monumental pain in the ass that rails hands you by putting your model, controller, and view files in separate directories. No other project I know of does anything this idiotic. You will quickly get annoyed (or worn out) having to "cd" back and forth between directories unless you work up some kind of scheme for dealing with this. A linux setup with multiple virtual desktops and multiple terminal windows can be used to reduce the tedium.

What I did was to write the following short shell script and put it into my own ~/bin directory as "trails":

#!/bin/sh

# Rails script  11-6-2012 tjt
# start up a flock of windows to make editing rails more sane.
# (this is using the xfce4-terminal under Fedora 17).

RAILS_ROOT="/u1/rails/tutorial/sample_app"
TERM="terminal --maximize"

$TERM --title=rails --working-directory=$RAILS_ROOT
$TERM --title=app --working-directory=$RAILS_ROOT/app
$TERM --title=views --working-directory=$RAILS_ROOT/app/views
$TERM --title=models --working-directory=$RAILS_ROOT/app/models
$TERM --title=controllers --working-directory=$RAILS_ROOT/app/controllers
$TERM --title=spec --working-directory=$RAILS_ROOT/spec

# THE END
This gives me 6 windows, all sized full-screen, with titles set appropriately. I am using xfce4-terminal (which under Fedora 17 is "/bin/terminal"). Under xfce, this effectively gives me 6 "buttons" across the top of the screen that I can click on to switch between terminals. The one labelled "rails" I use to either run tests, run "rails server", do git stuff, run the rails console, install new gems and that sort of thing. The one labelled "app" has proven useful for things that don't fit into the next four. The rest should be self explanatory. If you use helpers, partials, or things like that you do have to hop around a bit within views or controllers, but this is a huge improvement over using a single directory and typing "cd" till you are going insane.

If you are using Gnome 3 (or, heaven forbid, Windows), you will need more help than I can give you.


Feedback? Questions? Drop me a line!

Ruby on Rails notes / [email protected]