Saturday, May 21, 2011

A little late-night coding

I wish I didn't have to get up at 7 am during the week. I've always felt most productive and focused when working on projects late at night.

I've been reading the archives at lately. I'm using some liberty when I say "reading the archives," because I really only got to this article on good Rails tutorials.

On a side note: I've linked to a 5 year old article which is a link to another article which is a collection of Rails tutorials. Is that ridiculous?

ANYWAY! My friend Eli encouraged me to try out some of these tutorials, despite their age. Most of them use bizarre, antiquated syntax. Luckily, I found an updated version of the first tutorial, which walks you through creating a recipe database. It's a simple application, allowing a user to create recipes and categories, then assign recipes to categories. I can think of several ways to expand functionality for this application: allowing users to search by ingredients, sorting recipes by categories, allowing users to create meals consisting of multiple recipes and so on.

I try to think of these things when I'm doing a tutorial or working on a personal project. I always ask "What else could be done? Where else could this go?" Luckily, Rails not only makes it easy to build something functional very quickly, it also makes adding functionality easy. I'm not sure if this is true for most other languages, but I highly doubt I'd have gotten interested in Rails if it wasn't so simple to pick up the basics.

Not that I think I'm an expert, or even knowledgable! I still get discouraged, especially when I can't figure out how to do something that SHOULD be easy, but I'm getting better every day. I'm planning to work through some of the tutorials on that list, hoping to learn some techniques that I can apply to Manticore and other projects.

A couple of interesting things I learned tonight:

Linking back to the main page of an application:

I got on irc and asked about this. It turns out the trick is this:

<%= link_to 'Home', :root %>

I'd tried linking to various forms of home, index, homes_path and index_path with no luck. This nice little trick saves a bit of time when navigating, though in a real application I'd want to use breadcrumbs instead. I'm assuming that would be built in much the same way?

Pulling information from one model and displaying it in the form of a second model:

In this application, I have two models: Recipe and Category. Each Recipe will belong to a Category, and to build this information in the form for a new Recipe, here's the code:

<div class="field">
  <%= f.label :category %><br />
  <%= select "recipe", "category_id", Category.find(:all).collect {|p| [, ] }, {:include_blank => true} %>

It feels good to make progress, and I think I should be talking more specifically about what I've learned. I feel like my learning has been all over the board, but maybe that's how everyone learns to code.

No comments:

Post a Comment