Victus Spiritus

home

Walking down the tracks with Ruby on Rails

15 Nov 2009

A Sea of Glass - The Chihuly Exhibit at the Ballagio in Vegas
this is a follow on post to Pigs may not have wings, but I can Ride the Rails with a flu

Gems Gems Gems

The first barrier to entry to ramping up on RoR (Ruby on Rails) was setting up a build environment. I found several windows friendly developmet options. Netbeans has an install. Steel Ruby has a visual studio variant, Instant Ruby creates an environment you can drop rails projects into (instantly ;)), and Ruby Forge has an executable for windows machines. I opted for the Ruby Forge windows exec after trying the other routes to varying degrees of success. Primarily because it almost works (there's no shuffle! Array function on the RoR Ruby Forge version, or my environment still has problems), it's command line driven, and I know where the common install/gem folder is.

Let me warn potential windows RoR coders that while all of these options may work to varying degrees, if your ultimate server destination is Linux Apache, you may save a lot of headaches by setting up a dual boot Ubuntu installation (today's plan for me). After running into the bug with shuffle! and spending time finding and understanding it, your very limited learning and development time would be better served by avoiding the additional complications introduced with a different OS. Keep in mind I had a much more learned co-pilot helping me along in understanding using Adobe Connect.

Darn GEMS!

There are inconsistencies in gem names, versus the gem packages. This is to avoid name conflicts because gems sit in repositories on public facing web servers. I also found several close variants of gem names that have subtle implementation differences. One of the pitfalls I fell into was in assuming I had to call rake, and pass all our unit tests. It turns out I assumed wrong. In the race to develop something that is valuable to users, we have opted to skip some of the long term habits Rails nudges us towards (I'm sure as time allows we'll find our way to testing). So the tests weren't setup quite right for our specific project (they were using sqlite a default database for rails while we use MongoDB, a new NonSQL database option).

MVC Directory Structure First Timer

MVC stands for:

When you first construct a bare bones Rails app (rails hello) , the folder structure looks something like this:
C:\Users\Dude Jones\Desktop\My Dropbox\Mystuff\people>tree
C:.
├───app
│ ├───controllers
│ ├───helpers
│ ├───models
│ └───views
│ ├───layouts
│ └───people
├───config
│ ├───environments
│ ├───initializers
│ └───locales
├───db
│ └───migrate
├───doc
├───lib
│ └───tasks
├───log
├───nbproject
│ └───private
├───public
│ ├───images
│ ├───javascripts
│ └───stylesheets
├───script
│ └───performance
├───test
│ ├───fixtures
│ ├───functional
│ ├───integration
│ ├───performance
│ └───unit
│ └───helpers
├───tmp
│ ├───cache
│ ├───pids
│ ├───sessions
│ └───sockets
└───vendor
└───plugins

Here's that same structure with files
C:\Users\Dude Jones\Desktop\My Dropbox\Mystuff\people>tree /f
C:.
│ Rakefile
│ README

├───app
│ ├───controllers
│ │ application_controller.rb
│ │ people_controller.rb
│ │
│ ├───helpers
│ │ application_helper.rb
│ │ people_helper.rb
│ │
│ ├───models
│ │ person.rb
│ │
│ └───views
│ ├───layouts
│ │ people.html.erb
│ │
│ └───people
│ edit.html.erb
│ index.html.erb
│ new.html.erb
│ show.html.erb

├───config
│ │ boot.rb
│ │ database.yml
│ │ environment.rb
│ │ routes.rb
│ │
│ ├───environments
│ │ development.rb
│ │ production.rb
│ │ test.rb
│ │
│ ├───initializers
│ │ backtrace_silencers.rb
│ │ inflections.rb
│ │ mime_types.rb
│ │ new_rails_defaults.rb
│ │ session_store.rb
│ │
│ └───locales
│ en.yml

├───db
│ │ development.sqlite3
│ │ schema.rb
│ │ seeds.rb
│ │ test.sqlite3
│ │
│ └───migrate
│ 20091111235941_create_people.rb

├───doc
│ README_FOR_APP

├───lib
│ └───tasks
├───log
│ development.log
│ production.log
│ server.log
│ test.log

├───nbproject
│ │ project.properties
│ │ project.xml
│ │
│ └───private
│ private.properties
│ rake-d.txt

├───public
│ │ 404.html
│ │ 422.html
│ │ 500.html
│ │ favicon.ico
│ │ robots.txt
│ │
│ ├───images
│ │ rails.png
│ │
│ ├───javascripts
│ │ application.js
│ │ controls.js
│ │ dragdrop.js
│ │ effects.js
│ │ prototype.js
│ │
│ └───stylesheets
│ scaffold.css

├───script
│ │ about
│ │ console
│ │ dbconsole
│ │ destroy
│ │ generate
│ │ plugin
│ │ runner
│ │ server
│ │
│ └───performance
│ benchmarker
│ profiler

├───test
│ │ test_helper.rb
│ │
│ ├───fixtures
│ │ people.yml
│ │
│ ├───functional
│ │ people_controller_test.rb
│ │
│ ├───integration
│ ├───performance
│ │ browsing_test.rb
│ │
│ └───unit
│ │ person_test.rb
│ │
│ └───helpers
│ people_helper_test.rb

├───tmp
│ ├───cache
│ ├───pids
│ ├───sessions
│ └───sockets
└───vendor
└───plugins

There are scripts that will populate subdirectories with ruby files. One that adds to the application, model and view folders at once is scaffold.
It looks like this on a windows prompt:

ruby script/generate scaffold person name:string password:string email:string age:integer

It creates several files of which I believe a few are key after reading some of getting started (I prefer to learn by doing, then going back to understand what I did worked or broke and why):

The scaffold script also generates several tests (look for person/people above, a helper).

IDE

I used Netbeans, Visual Studio, and for editing Notepad and ScITE. Of all of these, I think I prefer Visual Studio the best for speed, style and responsiveness, but Netbeans is a good backup integrated development platform. ScITE was handy for quick editing though. I ran the server off of the console so I can see what messages (errors) it was printing out, instead of constantly have to reopen the log file. I suspect you will become quite intimate with log/development.log as you experience building your own Rails projects.

Check out what we're up to at Victus Media, a cool dev build should be going live this week for Intelligent Advertising Media.

Don't forget this handy Google Doc I started for diving into Ruby on Rails.

[iframe http://spreadsheets.google.com/pub?key=tC8t8DLTN4vmhQAY-NcnNbA&output=html 480 600]