Rails


Leopard comes with Rails, but I prefer to roll my own in an effort to keep my environment stable. As always Hivelogic has the goods:

Gregg Pollack, of Rails Envy fame, gave a good presentation on REST web services at the Orlando Ruby User’s Group recently (video here). This is a great primer for anyone trying to figure out what all this REST stuff is about. He also touches briefly on a couple Rails 2.0 features like ActiveResource.

Fallen Rogue has a succinct tutorial on implementing drag & drop lists on Rails. It also touches on implementing acts_as_list. This tutorial and the referenced sample application was good way to get drag & drop lists working quickly in my own application.

The PDF version of Build Your Own Ruby on Rails Web Applications by Patrick Lenz is available for free for the next 60 days. Click over to Sitepoint to download the complete book (20MB). The book introduces Ruby on Rails to aspiring Rails developers by showing them how to build a Digg clone step by step. In the process it touches on many important concepts such as test driven development.

via Riding Rails

This Nested resource CRUD tutorial does a great job of quickly explaining how to get a nested resource working in a RESTful Rails application. If you want some more detail, this RESTful Rails Development PDF covers more while still remaining succinct. It is worth a read, even for non-rails developers, since it explains more about how REST works. Especially helpful is the explanation of how the HTTP verbs are used to call different actions in the controller.

Learn from my mistake and don’t forget to modify the nested controller’s create action. This is noted in the PDF but not the post. Left unmodified, the create action will insert the nested records (in this case, “comments”) with NULL foreign keys in the database.

There are a couple ways to fix this. I’ll keep with the posts/comments example in the code snippets below. The method used in the PDF simply adds one line of code to explicitly set the parent id as shown in bold below:

def create
	@comment = Comment.new(params[:comment])
	@comment.post_id = @post.id
	. . . .
end

The other way, which I prefer, is to replace the call to the comment’s new method with a call to the build method as shown in the following code:

def create
	@comment = @post.comments.build(params[:comment])
	. . . .
end

This accomplishes the same thing in one line rather than two, therefore, I like it. Thanks to Ryan for pointing this out on railsforum.

This Ruby on Rails security guide pulls together several excellent sources on securing Rails applications. It is broken down by category (authentication, model, controller etc.) so it makes for a great reference.

via Ruby Inside

Writing code without using version control is the equivalent of swinging on a trapeze without a net. Sure, if you execute each move flawlessly, you’ll be fine. But, one wrong move and you’ll fall to your death. Okay, coding mistakes rarely lead to injury or death–of the programmer anyway–but I think you see my point.

There are loads of version control systems out there. Subversion, however, is the weapon of choice for most people working with Ruby on Rails. If you are unfamiliar with Subversion, the Subversion book is a good place to start (print version available on Amazon). The first part of this book gives a good overview of what version control is all about, so those totally unfamiliar with the concept can jump right in.

As for Ruby on Rails applications, they can just be checked into version control like anything else. But, there some files and directories that don’t really need to be under version control. There is an easy, step-by-step guide on using Subversion with Rails at the Rails wiki. Following these instructions takes less than five minutes and will keep your repository free of extraneous files (e.g. log and temp files).

With your Rails application under version control, you can rest easy knowing that you have some recourse when your latest code update breaks everything. Just don’t forget to commit your changes on a regular basis or this is all for naught. Also, remember that the Rails generator scripts accept an --svn option which will automatically add generated files to your repository. This will save you the step of adding these files manually later on.

In addition to giving you a sort of coder’s safety net, using Subversion gives you the ability to automate application deployment with Capistrano if you wish. So, now you have two excellent reasons to get your application into Subversion. By the way, if you are looking for a place to store your repository, check out CVSDude. They offer several monthly plans, including a free one.

Rails Envy has a great screencast tutorial on ActiveRecord. Gregg does a great job explaining a couple concepts that can be difficult to grasp like has many :through and polymorphic relationships. This is well worth watching for anyone new to Ruby and Rails. Even if you are not working with Ruby, it is a good way to see how Object-relational Mapping is achieved in Ruby with ActiveRecord.

via Ruby Inside

You’ll only need to be mildly geeky to appreciate this Get a Mac inspired ad.

Click to play video

I wonder what’s in that final, mysterious jar? Kool-Aid perhaps?

via Riding Rails

Update 2006-05-16: These guys are posting an ad a day leading up to RailsConf 07. See the rest of the Envy ads on youtube.

Rather than enjoying a long awaited Spring Saturday in New York, I was at the first–and hopefully annual–Gotham Ruby Conference. Although the great weather was enticing, the conference was well worth the day spent indoors. The fact that it was at Google’s NYC office didn’t hurt.

The organizers of this conference deserve a huge, collective pat on the back for a job well done. This was one of the best organized events I’ve attended. No small task for a group of people that have day jobs and many extracurricular activities. Nice work all.

Here are my brief notes, for more detailed coverage of the talks, check out Bryan Helmkamp’s blog.

Adhearson: “Build your own PBX on a Weekend” (video)
Jay Phillips

Adhearsion is a Ruby layer on top of Asterisk. This talk got a lot of people in the room excited about the possibility of doing VoIP with Ruby. That’s good because Jay said he would like to hook up with some rails developers that are interested in Asterisk integration. This is very cool stuff. I personally would welcome one of the items off of Jay’s “future” slide: RSpec testing… for a PBX!

Resources:

JRuby: Ready for Prime Time (video)
Nick Sieger

JRuby is a version of Ruby that runs on the Java Virtual Machine. JRuby running in interpreted mode is still a bit slower than C Ruby. However, in compiled mode, it tends to run a bit faster in many cases. Release 0.9.9 should be available next week.

Going Camping (video)
Jeremy McAnally

Camping is a web microframework (4K) and in short, it’s “Rubylicious”. It is a MVC framework, but unlike rails, all of the application code goes in one file by default. Camping is good for those occasions when Rails is just too fat. Some other differences are that views are constructed in Markaby rather than ERb and Camping defaults to SQLite but using another RBDMS is certainly possible. Jeremy is working on porting some other very useful Rails modules to Camping.

Categorizing Documents in Ruby (video)
Paul Dix

This is a topic I am currently very interested in. Document categorization is used quite a bit for spam detection today. It is also quite useful for language identification, news categorization and sentiment detection.

At a very high level, the steps for machine categorization are as follows:

  • Get training data
  • Document preprocessing
  • Feature selection (optional, increases accuracy)
  • Train the Classifier
  • Test and update

Yes, that is very high level. Once again, get the details of the talk here.

For those wishing to get started with document categorization, Paul suggested the Naive Bayes Classifier since it is fast and forgiving. He said he would post has posted some of his categorization code on his site, including his Chi Squared feature selector.

Contexts, Mocks and Stubs. Oh My! (video)
Trotter Cashion

Trotter’s talk was very detailed and chock full of examples, my notes are quite sparse here though. The best thing I took away from it was to avoid going nuts when writing tests. Basically, test thoroughly and ensure good coverage, but be careful not to write too many tests or make them too brittle. Also, sometimes it is better to create a class for testing rather than to use mocks and stubs.

He also pointed out Ryan Davis’ Functional Test Matrix which looks quite interesting indeed.

Business Natural Language Ruby Systems (video)
Jay Fields

The idea behind Business Natural Language (BNL) is to put the power of changing business rules into the business expert’s hands rather than involving software developers for every change. Jay’s BNL site explains this much better than I can, so I won’t attempt to go into detail here.

One final note: Having the Lightning Talks directly after lunch was a great idea. It can be difficult to stay focused, or awake, during a long presentation after lunch. Short, five minute presentations by different people keep it lively.

Technorati tag:

Next Page »