occasionally useful ruby, ubuntu, etc

24Jul/120

Quick Start with Sequel 3 in Rails 3

This guide is using Rails 3.2.6 and Sequel 3.37.0. If you're using a different version, these instructions may not quite apply.

Edit: realized this morning the title was ambiguous, so I updated it to reflect the Sequel focus.

Here's the easiest way to get going with Sequel in Rails:

23Apr/080

Ruby + Ruby on Rails tutorial

Note that this isn't finished and may never be finished, but I didn't want it to stagnate in my Proofs box any longer. So take what you can from it.

You, like me, have probably heard all of the hype around Ruby on Rails. "Convention over configuration" they say, and "Don't Repeat Yourself" are common Ruby on Rails adages. Well, it's true. Creating a new database is as simple as telling Rails your database credentials and typing a single command. Adding new tables takes just a single command.

When I set out to learn Ruby on Rails, I was beset with a bit of confusion. Rails 2.0 was released recently (December '07) and Ruby 2.0 is coming out soon. As a result of the Rails thing, there are a lot of out-of-date tutorials out there. So hopefully this will help someone out there trying to learn Rails right now.

Audience: Some programming experience (preferably web programming), but no Ruby/Rails experience.
Any operating system, but some bias towards Linux/Ubuntu
Goals:

  • Set up a development environment for Ruby and Rails
  • Write hello world in Ruby
  • Learn some Ruby syntax
  • Learn some Rails commands
  • Write hello world in Rails
  • Output data from a database
  • Take form data and update a database
  • Introduce Rails API for flash, style, javascript
  • Introduce flash variables
  • Apply style sheets
  • Apply javascript files
  • Prepare for future (Ruby 2.0)

Finally, this tutorial uses the following technologies and versions:

  • Ruby: 1.8.6
  • Rails: 2.0.2
  • Rake: 0.8.1
  • Rubygems: 1.0.1

If you're still interested, read on!

30Mar/080

jQuery :(

I wish Rails wasn't so intimately tied with Prototype+scriptaculous. It makes jQuery that much harder to use. Even so, using page << and jQuery is much easier than trying to use Prototype to achieve the same end. Not to be a fanboy or anything, but is there any other library out there that can remove a specific option from a dropdown select box in one short line of code?

24Mar/082

Simple Easy AJAX Form Validation in Rails

I'm using Ruby 1.8 and Rails 2 for this.

Thanks to BigSmoke for both the ActiveResource::Errors hint as well as inspiring me to look for another way.

What this method does is create and populate an error div with the specific error messages that occurred, and then destroy the div when the user submits a valid entry.