From the meetup I attended, I’d learned that there exists a significant amount of reliance on convention and “magic” in the Rails and Ruby community. Only today have I realized exactly to what extent the magic exists.

To illustrate that, I’ll show you an example from my daily Two Hours of Code.

I was working on my very first major Rails app, Syntag. Syntag is meant to be a crowdsourced snippet collection which will integrate with many major editors. First, though, I want to create a web interface which doubles as an API point.

To create my database, all I had to do was type “rails g model snippet” and it generated a class skeleton for my model and a “migration”, which is a small file which keeps things database independent and defines what exactly is in your table. Tables take on another name effectively as “Models” which are friendly ways to access your database tables.

My two migrations for my Language and Snippet models are as follows:

class CreateSnippets < ActiveRecord::Migration
  def change
    create_table :snippets do |t|
      t.string :title
      t.belongs_to :language
      t.text :contents
      
      t.timestamps
    end
  end
end
class CreateLanguages < ActiveRecord::Migration
  def change
    create_table :languages do |t|
      t.string :name
      t.string :highlighter_name
      
      t.timestamps
    end
  end
end

My point here is that this was the only code I had to write to have Rails generate a database for me with “rake db:migrate”, and it’s totally DB-agnostic.

As for a project progress report, I have finished basic interfaces for people to add snippets by language and to select a snippet. Tomorrow’s goal will be to work on getting it completely functional and perhaps working on the visual component of the application, cause it just currently isn’t very appealing.

You can see this project’s progress and commit log at it’s Repo On GitHub