Hugh Sasse's Ruby on Rails notes

These are notes for Ruby on Rails.

How to call the scaffold generator

% ruby scripts/generate scaffold Model Controller view [view ...]

Default views are available for index, list, show, new, create, edit, update, destroy. The scaffold generator will add the views for the model and add the actions to the controller.

In the models for model m has_many x means that there ae many records in table x which point to the same record in table m. has_one means that there will only be one. belongs_to_{one,many} are much the same. (Difference in semantics == what?)

How to call the model generator

% ruby scripts/generate model Model

This just generates the model, not the controller...

How to call the controller generator

% ruby scripts/generate controller Model [view ...]

This just generates the contoller and stubs for the views, not the model...

Pluralization in Rails

Tables are plural, models are singular. How rails figures out what the plural of a noun is can be figured out from the Inflector. I found out about this tool from http://www.slash7.com/articles/2005/11/17/rails-howto-pluralizing. You invoke the script/console and use Inflector.pluralize("noun") or Inflector.singularize("noun") or Inflector.ordinalize("noun") or Inflector.humanize("thing_with_underscores").

How to use KirbyBase with Rails

This is detailed in the blog Is your house on fire, Clark?, though why it is called that I don't know.

Using Rails with SQLite (SQLite3)

SQLite is a file based database with minimal configuration (approximately zero) requirements with acceptable performaance for most web applications. This is likely to be faster than KirbyBase because it is based on C rather than Ruby, but that is basically a guess. I can find no speed comparisons that are recent.

There is an sqlite3 gem packed by _Why mentioned on RedHanded. It is a rationalized repackaging of sqlite3-ruby from Jamis Buck.

There is a SQLite3 database browser including a version for Windows. This is not a GUI based admin client.

Plugins I've found useful

fixture_references plugin. Makes foreign key references between tables easier to handle. See: http://www.pluginaweek.org/2007/04/07/14-fix-your-fixtures-with-fewer-foreign-key-ids/ for more about this.

deprecated plugin. This finds deprecated constructs in your rails code, and provides hints as to what should be used instead.


Created by Hugh Sasse on 01-NOV-2005 .

Last Modified by Hugh Sasse on 08-AUG-2007.