Learning Rails. Again.
I’ve decided to remind myself of how good Rails is as a development and prototyping framework after my 6-month dalliance with the Semantic Web.
Picking up my dusty PragProg tome (Agile Web Development with Rails, Third Edition) I got down to business with hacking together their example of a web site cart, which will hopefully refresh my knowledge of all the Rails essentials whilst building something vaguely useful.
Task A was building a product maintenance screen - took me about an hour.
The steps included:
- Creating a development database (SQLLite3) and configuring the Rails application to access it.
This step was almost trivial - I’ve forgotten how easy a Rails scaffold is to implement, although I’m still thinking that its main purpose is to convince newbie Rails developers that ‘Hey, Rails is easy’!
- Used migrations to create and modify the schema in my development database and to load test data.
Already, I can sense that migrations are a really cool way of tracking change in a development - the Rails framework ‘knows’ how to apply changes based on the UTC timestamp on the migration file. Using a migration script to load in test data is really handy, as all entered data gets wiped upon each reload.
- Created a products table and used the scaffold generator to write an application to maintain it.
With Rails, it’s a one-line script to generate the scaffold, which does 90% of the work. However, then you spend the next 30 mins editing the scripts…is it faster to create from scratch…?
- Augmented the generated code with validation.
Since Rails is MVC (Model-View-Controller)-based, all of the validation so far is in the model (products.rb) - again, adding checks for presence, ‘numericality’ (love that) and custom logic is really nice and straightforward…custom functions dip into hand-coded Ruby so it’s nice to get a refresher on that too.
- Rewrote the generic view code with something prettier.
Well…copied some files from the Pragprog.com website…not sure *I* did much here, but it sure does look purrrrty! :-)
Will update more when I move onto the next task - Catalog display.