Open Mic Night At CVREG Tonight

Tonight the Central Virginia Ruby Enthusiast Group will be hosting an Open Mic night. Anyone attending will be able to jump up and give a 5-10 minute lightning talk about a topic they're excited about.

If you haven't been to a CVREG meeting, tonight would be a great time to visit and introduce yourself. The meeting starts at 6:00, but you can show up at 5:30 if you want to hang out and meet everyone.

All the relevant information can be found at the event's Upcoming page

Hope to see you there!

Popularity: 14% [?]

    Categories: Rails, Ruby     No Comments »
    Tags:

BDD’n All Over The Place

I've been working on quite a range of different projects recently, not all of which are Ruby/Rails.

One is in PHP and one is a cross platform widget that will work for the Yahoo Widgets engine as well as OS X's Dashboard.

Of these two projects I've managed to work some BDD into both of them. I thought I'd spread the word on the packages I'm using. For javascript I'm using JSSpec and for PHP I'm using PHPSpec

Neither are documented very much, and both are less than 6 months old. They're limited, but I've been able to get what I need out of them and its been nice to be able to keep the same dev style even if I have to deal with JS and PHP.

Here's a couple pieces of syntax.

PHPSpec

<?php
 
class DescribePage extends PHPSpec_Context{
 
  public function before(){
    $this->p = new Page();
  }
 
  public function itShouldReturnAShortUrl(){
    $this->p->url = "http://www.apple.com/imac/features.html";
    $this->spec($this->p->short_url())->should->be('www.apple.com');
  }
 
 public function itShouldNotBelongToAQueryWhenCreated(){
   $this->spec($this->p->query)->should->beNull();
  }
 
}
 
?>

JSSpec

describe('Get Song From XML', {
  before_each : function() {
    podcast = new Podcast()
    podcast.xmlUrl = 'podcast_xml_fixture.xml';
  },
    'should parse song title from xml': function() {
      topTune.readFeed();
      song = podcast.parseTune();
      expect(song[0]['title'].strip()).should_be("Willoughby - Frankenstein");
  },
      'should parse song url from xml': function() {
        podcast.readFeed();
        song = podcast.parseSong();
        expect(song[0]['link'].strip()).should_be("http://www.domain.com/featured/willoughby_-_franken");
  },
      'should create song': function() {
        podcast.getSong();
        expect(podcast.song).should_not_be(null);
    }
})

Popularity: 13% [?]

    Categories: Javascript, PHP     1 Comment »

Display Validation Errors For Your Ajaxified Form

One of the sweet things Rails provides is practically free error notification on forms. With just a little bit of

<%= error_messages_for :post %>

validations on your model, and some logic in your controller, bam, instant error messaging. Very simple.

But what if your form is using AJAX to post? The page doesn't re-render, so how is our buddy, error_messages_for, going to work? Well its not, we're gonna have to use AJAX to display the errors. It turns out this isn't too touch, but as usual we want to keep it DRY.

The Controller

class PostsController < ApplicationController
  def create
    @post = Post.new(params[:post])
    @post.save!
 
    # automatically renders create.rjs.erb
 
  rescue ActiveRecord::RecordInvalid
 
    @model = @kit_item
    render :template => 'shared/validation_error.rjs.erb'
 
  end
end

We will attempt to create the Post. If all goes well, then the create rjs action will fire and all is well. But if the record fails validation, we catch it, assign the current model to @model, and render shared/validaiton_error.rjs.erb. This is our generic AJAX action for rendering errors for Models.

The AJAX

Create shared/validation_error.rjs and use this little snippit, and thats pretty much it for this part.

page.replace_html "errors_for_#{@model.class.name.underscore}", "Oops! <ul>" + @model.errors.collect{|k,v| "<li>The #{k} #{v}</li>"}.to_s + "</ul>"
page.visual_effect :highlight, "errors_for_#{@model.class.name.underscore}", :startcolor => "'#ff0000'", :endcolor => "'#aca2b6'"

So, the errors just get collected and printed out to a div in the page. Let's go add this fancy div.

The View

This part is pretty simple. You just need to open up your form partial, posts/_form.html.erb and add this little view helper to the form:

<%= error_div_for post %>

This does nothing but prints out a div with a specific ID to prepare for our RJS action, if it's needed. So let's go make the view helper.

module ApplicationHelper
 
  def error_div_for(model)
      %{<div id="errors_for_#{model.class.name.underscore}"></div>}
  end
 
end

Now we can just call this simple view helper and pass in any model and it will dynamically build a div with the appropriate ID inside.

And thats pretty much it. To go through it again, when the form is loaded, the error div will be placed in the page, waiting to be used. Once the form is submitted in the background, the controller's create action will attempt to save it. If the record is invalid with validation errors, then the universal validation_errror RJS template will be fired off and replace all the errors from the failed validation, into the div we placed in the page. Oh and of course a little red flash action to make sure the user sees the errors.

Popularity: 15% [?]

    Categories: Rails     7 Comments »

Use Your Basecamp Feed Under Leopard’s Mail.app

Ok, here's another tip for Leopard. I may need to add a new category to this weblog, or maybe just stop spamming my dev blog with these posts. But I will argue that these are all tools that us web devs use.

I have a lot of feeds, and I like to use them in different ways. My basecamp is one of those feeds that isn't so much information based, as much as it is notification based. Because of this, I want to use it in Mail.app.

Simple enough, ok... add feed, and... oh wait a second...

Sweet. Thanks Apple. You were smart enough to know the feed was protected by http auth, but not cool enough to prompt me for the username/password combo.

This solution might be obvious to some, but not to others, so I thought I'd post it anyways. To get your feed working, just overload the URL with your username and password.

http://myusername:mypassword@company.projectpath.com

Mail.app will pull in your feed as normal. But what if you're a hipster using openid!? Click to the My Info section of Basecamp and you'll find a whole section devoted to this. Basically, you'll use your openid as a username and Basecamp provides you with some kind of hashed password.

http://jonmaddox.myopenid.com:34kjlk3kk3kl3jkl43@company.projectpath.com

Yeah, simple, but someone's gonna get stuck.

Popularity: 8% [?]

    Categories: Snippets     2 Comments »

Flush your DNS Cache in Leopard

As a web dev, you may spend some time messing with DNS and overriding it. Though, it can get annoying when you can't get things back to the way that mere mortals see things on the internet.

lookupd -flushcache was a big tool in my arsenal in Tiger. But Leopard put a rightful end to lookupd, but left us without our known way of flushing the cache.

For the last couple of weeks its been pretty annoying, but I'm here to bring you, the NEW way to flush dns cache for OS X users!!! Holy crap this is exciting.

So it's as simple as this:


dscacheutil -flushcache

There you have it.

Popularity: 16% [?]

    Categories: Snippets     9 Comments »