Category Archives: Ruby on Rails

Honolulu Coders

If you are a programmer in Honolulu, you should check out the Honolulu Coders group. The meetings happen roughly monthly on a Wednesday at the University of Hawaii at Manoa POST building and cover a wide range of topics, including Java, Ruby (on Rails), and new trends in software development. There is a web page with some information on past meetings (requires registration with disCourse), and there is an iCal feed for future meetings.

Tonight’s meeting will have a presentation on Meme Tools and Sam Joseph (the primary instigator) will be talking about his new iPhone and “how it sucks” [for using web apps that require drag and drop 🙂 ]

Oh yeah, and there is free pizza sponsored by Ikayzo. What more could you ask for?

Hopefully this blog entry will increase the chance that someone searching for “honolulu coders” will actually find useful information (right now the top hits are some references from another Hawaii mailing list, which is weak).

Advertisements

Securing MySQL for development

When developing in Rails, the canonical thing to do is to have a root MySQL account with no password. While this makes the Rails configuration automagic, it leaves things somewhat open because MySQL accepts TCP/IP connections by default. Note that this is separate from the webserver hosting the Rails application on localhost. It turns out that MySQL has a nice command line option --skip-networking, which will turn off all TCP/IP networking. Database connections from the local webserver will go through a Unix socket, so they will continue to work and that’s all you need for development.

I installed MySQL using the MySQL AB official binary distribution. However, I have been starting and stopping MySQL using the conveniently supplied panel for Mac OS X System Preferences, thus preventing my from adding any command line arguments. After some fiddling, it turns out that the preference panel is just calling the shell script /usr/local/mysql/support-files/mysql.server. This file (or one of the scripts that it calls) will read ~/.my.cnf or /etc/my.cnf for MySQL configuration options. To make it work with the pref pane, I had to put the following options in /etc/my.cnf:

# MySQL options file
[mysqld]
# turn off all networking, for safety during development
skip-networking

After that, MySQL is no longer listening via TCP, as confirmed with CocoaMySQL’s Show Variables, and via netstat -a. I feel safer already. 🙂

Happy Hacking Half-Hour with Pavel

Pavel and I did our 4H on Friday. I was in the driver’s seat, and decided to finish up the Rails tutorial that I presented the first portion of last Wednesday at the CSDL meeting.

We used the CSDL meeting area for our 4H, and since we were working through a tutorial we used the projector as a second monitor rather than a mirrored display: tutorial web page on the projector, Eclipse on the laptop display. This worked pretty well I think, and I would encourage it as an option for other 4Hs.

As for what was learned, the rest of the tutorial had more actual Rails coding and went more into modifying view pages in RHTML.

P.S. I forgot that we were supposed to spend the last 5 minutes blogging about it, so this is a belated blog entry.

MySQL installation and configuration

Most Rails tutorials use MySQL as their canonical database. Locomotive includes SQLite, but not MySQL.

The consensus seems to be that installing MySQL via the official Mac OS X MySQL installer is the best way. It installs in /usr/local/ and includes a System Preferences pane for easy startup and shutdown.

MySQL installs with 4 accounts (including 2 root accounts) that have no password. While the default install only allows connections from localhost, it’s still a good idea to set the passwords to something. MySQL AB has a help page on Securing the Initial MySQL Accounts.

For manipulating MySQL databases directly, the open source CocoaMySQL seems nice. I used it to secure the initial MySQL accounts: Tools->Edit User.

Ruby on Rails tutorials

Here’s a bunch of RoR tutorials from the web. The canonical book on the topic is Agile Web Development with Rails.

Ruby on Rails development on Mac OS X

Getting RoR installed is pretty easy with Locomotive, an entirely self-contained RoR environment for Mac OS X (there is a Windows equivalent called Instant Rails). This means no installing all the pieces, and no messing up of anything in Mac OS X (which includes Ruby these days). You just drag the application into your Applications folder and you are good to go. However, it also means that any other tool or application that needs to call Ruby has to be configured to use the version installed inside Locomotive (which is really a bundle that includes the application and all the RoR components).

The hip text editor for RoR on the Mac is TextMate. However, it’s a commercial application and has no API for Hackystat hooks, so I’m avoiding it for now.

The best alternative (for Eclipse users) appears to be RadRails. It’s available as a standalone editor (a customized version of Eclipse) or as an Eclipse plugin. Annoyingly, RadRails is currently in transition as Aptana (a company that makes an open source JavaScript/AJAX editor plugin for eclipse) takes over the development from the original developers. This means the documentation and website is a bit of a mess right now.

Pieced together from various web pages, here is how to get up and running with RoR on Mac OS X (assuming you have Eclipse 3.2.X already installed):

  1. Download Locomotive and drag the Locomotive icon into your Applications folder.
  2. Install RDT and RadRails Eclipse plugins. Aptana has the links in their RadRails docs.
  3. Configure RadRails to use RoR embedded in Locomotive. Due to the RadRails documentation transition right now the wiki with the instructions is only available from Google’s cache, but here it is from some blog. Note that Preferences will be under the Eclipse menu (not RadRails, the customized Eclipse version), and that the exact paths will be different based on what version of Locomotive you have (the release date is part of the path, ugh) and whether you are on an Intel-based Mac (select “i386” path) or a PowerMac (select “powerpc” path).

After following my instructions I was still getting weird errors in RadRails when trying to create a HelloWorld project. I think the key is to do the RadRails configuration before creating any projects. Remember that Eclipse configuration follows the workspace, so if you create a new Workspace for RoR work then make sure you do that before you configure RadRails to use the Locomotive paths.