A Little More on Rails

Last week I started talking about giving Ruby on Rails a try, and I had planned to have plenty more to say for this post. I have a printed copy of the great looking Four Days on Rails guide sitting on my desk, and I’ve been looking forward to digging in.

Unfortunately, aside from a minor quest to figure out how to customize IDE syntax highlighting, the experiment took a bit of a backseat this week. So, I’m going to go back to what I learned the previous week and share something from the starter tutorials that really got me excited about working with the framework.


So, how do you get basic database maintenance pages with one line of code? To get right into the good stuff, I’m going to skip the bits about installing Rails and creating a Rails application. I’ll also assume that we’ve already changed our database.yml file to point the Rails application to our database, and that we’ve created a database table, "tests".

To get started working with a database table in Rails, the first thing we need to do is create a model and a controller object using a couple of server scripts:-

	$ ruby script/generate model Test
	$ ruby script/generate controller Test

If we then find the test_controller.rb file, and add the scaffold line so it becomes:-

	class TestController < ActionController
		scaffold :test

We’re done. That’s right, we now have functioning create, list, update, and delete web pages for the tests table. I don’t know about you, but I think that’s pretty cool, and it instantly made me want to learn more about Ruby on Rails.

That IDE Quest

Paul wrote a nice summary of Ruby IDE options here on Codesnipers back in September (I might take a look at Eclipse and UltraEdit), but the object of my desire this week was a Visual Studio or Dreamweaver syntax highlighting solution.

I felt like I was getting somewhere with Visual Studio when I found out that if I tell the IDE to treat ruby (.rb) files as C++ files, I can fill a usertype.dat file with Ruby keywords, and they will be highlighted. Unfortunately, I don’t think that solution would work for rhtml files, where I’d like HTML and Ruby keywords highlighted.

I did find something very promising looking for Ruby in Dreamweaver though (it even adds code hints), so I’ll let you know how I get on.


One to look at that wasn't mentioned in my writeup (since it wasn't out yet) is RadRails. It's built off Eclipse and RDT (an Eclipse plugin) and runs as a stand-alone IDE (you don't need Eclipse to run it). It's got highlighting for .rb and .rhtml files and a few other things. It's still pretty minimal at this point but they seem to be doing a lot of work and getting releases out every couple of weeks. You'll still miss Visual Studio but I'd say it's better than using VI and it's easier to get running than tracking down the multiple development tools you'd need to create a full IDE.


Thanks Paul, if I don't get anywhere with the Dreamweaver customisation, I'll be sure to give it a try.