« February 2007 | Main | October 2007 »
Learning Rails: Migrations Part 2
Summarizing what I've learned: 1) from application directory, run "rake db:schema:dump" to create a dump of the applications's data structure compatible with Migrations. It's called schema.rb and gets dumped in the \db directory. 2) Run "ruby script\generate migration BaselineSchema" to generate a Migrations file. 3)Edit the schema.rb to include version information. Change "ActiveRecord:: Schema.define() do" to "ActiveRecord::Schema.define(:version => 1) do". 4)Run "rake db:migrate" to actually to the work.
The script does the work, and in the process creates a table called schema_info in our database containing only one field, which is the version number of the database's current schema according to Migrations.
We have a baseline established, basically an empty migration. From now on, we can call the migrations by what they do and start building out our database!
Again, run "ruby script\generate migration MyMigrationName" Edit this file to define your changes and how to reverse them. Run this file using "rake db:migrate".
Note: In the tutorial I'm working through, the change defined in the first migration after the Baseline contains an error. The self.up method in the tutorial says add_column("Recipes", "contributor_name", "string" :default => "Unknown") while it ought to say add_column("Recipes", "contributor_name", :string, :default => "Unknown"). The tutorial's code will fail to run on my version of InstantRails.
Note to self: find out whether the long run time of "ruby script\generate migration Foo" is due to my system itself, my InstantRails, or if it's intrinsic to the process. I see that the Ruby.exe process is what's hitting the CPU pretty hard. Likewise with rake db:migrate. Perhaps this is due to loading the Ruby interpreter each time, like back when I was working with Java and experienced some harsh JVM startup times.
Now we can arbitrarily roll back to any previous version: rake db:migrate VERSION=2
Cool stuff! The next tutorial in this series is located here ( http://www.oreillynet.com/pub/a/ruby/2007/06/28/cookin-with-ruby-on-rails---june.html) and works with Testing.
Posted on September 14, 2007 | Permalink | Comments (0)
LEarning Rails: Moving along to Migrations
I've wrapped up the first part of "Cookin with Ruby on Rails". It really seems like this is a pretty good framework for rapid, iterative development. But as a web developer experienced in other tools like ASP and JSP, I need to know a lot more about this before I am comfortable with the idea of doing actual work. The next part of the tutorial, dealing with Migrations and Unit Tests, looks like it's going to help me go in that direction.
Tutorial link: http://www.oreillynet.com/pub/a/ruby/2007/05/17/cookin-with-ruby-on-rails---may.html
Per the tutorial, Migrations will allow me to develop code against a database without worrying what database I'm using. Dealing with the database entirely through Ruby. Should be interesting!
The narrative style of these tutorials may be slowing me down, because I am not accustomed to working and learning in this way, but I feel that right now it's good to be out of my comfort zone and let my brain be stretched a bit. If I am slowed down too much, I may have to switch to another tutorial or document.
Posted on September 14, 2007 | Permalink | Comments (0)
Learning Ruby: Stream of Consciousness Posts
In this exercise of learning Ruby, I am creating blog posts that are much more overtly stream-of-consciousness than is normal for me. This is intentional, because I am using the blog as a way of taking notes while forcing my writing to occur in a particular way. Soon, I will add a tag to this sort of post so that if the style really bothers you, the posts can be skipped in favor of more coherent posts.
Posted on September 13, 2007 | Permalink | Comments (0)
Learning Rails: First Glitch
Okay, I'm at the point where we've generated our scaffolding, and I start Mongrel (the lightweight HTTP server, perfect for dev use). Mongrel starts up, binds to localhost:3000. I try to hit the URL http://localhost:3000/category, and get this:
no route found to match "/category" with {:method=>:get}
Yikes! I'm only on the beginning page, and I have some kind of error. Worse, I'm just starting out. But this is an excellent learning opportunity and brings to mind why we call an experienced person "seasoned" (do some research on cast iron cookware).
Looks like the scaffolding for the category table didn't get created....probably a problem with the connection between my chair and my keyboard, so I make sure that I run "ruby script\generate scaffold category category" once more.
Now I restart Mongrel, and I have a working app! Impressive. The tutorial can go on.
Posted on September 12, 2007 | Permalink | Comments (0)
Learning Ruby on Rails
Quick note: I'll be journaling my learning process in Ruby and RoR off and on via this blog, with the possibility of moving it elsewhere when I get a chance.
With my mixed OS environment I wasn't sure where to begin development, so I looked at my options and saw how InstantRails was, well, instantly available after dropping it into any directory (with no spaces in the path). So I'm beginning on Windows 2000. InstantRails is cool, it's kind of like using XAMPP for PHP development. In fact, InstantRails includes all the ingredients, even PHP!
Okay.... InstantRails works as promised, at least on my system. Unzip and run!
To begin learning, I am jumping in to this tutorial. I'm linking page two because that's where the meat begins: http://www.onlamp.com/pub/a/onlamp/2006/12/14/revisiting-ruby-on-rails-revisited.html?page=2
InstantRails 1.4 includes a completed version of the Cookbook app built in this tutorial and it looks like a decent starting point.
After the onlamp.com tutorial, I plan on moving into the "Four Days on Rails" tutorial by John McCreesh.
Posted on September 12, 2007 | Permalink | Comments (0)
iPod Touch, New Nano, iTunes Wifi
Following on the heels of the iPhone, Apple has released the iPod Touch - essentially an iPhone without the phone. What are we dealing with here?
I had long wished Apple would design something like the Nokia Internet Tablet, which runs Linux and uses a stylus interface. iPhone embodies that idea and adds a GSM phone. iPod Touch is more along the lines of the Internet Tablet itself, sporting a WiFi Internet connection and the Safari web browser, and even the YouTube app.
I'm seriously conflicted about whether to get the iPod Touch, requiring me to be tethered to WiFi (I'm a bit more mobile than WiFi allows sometimes) or whether to wait until my existing mobile contract runs out so I can get the iPhone without the ETF kicking in. One technical factor that may come into play is that I haven't seen any evidence of email capability on the iPod Touch, although I'm sure hackers will be working on app portability before too long.
One other thing I haven't seen is whether or not the WiFi connection could allow iPhone and iPod Touch to play AirTunes, or to access shared iTunes libraries when you're on your home network.
Along with all this, the Nano has gotten a nice bump - it can now play video and sports the new interface as well.
Considering the $200 US price drop within two months on the iPhone, I'm glad I took the wait and see approach thus far.
Posted on September 6, 2007 | Permalink | Comments (0)