Posts from April 2008

Getting Started with phpViddler

Over on the Viddler Lab blog, Colin Devroe and I are putting together a series on how to use phpViddler, the PHP wrapper for Viddler API. Parts one and two are already up, and more are on the way, so definitely check it out if you’re interested in developing a site powered by Viddler.

Posted on April 22, 2008 2 Comments
Tagged with: , , ,

Moon over Citizens Bank Park 1

Moon over Citizens Bank Park 1

Posted on April 19, 2008 2 Comments
Tagged with: , , , , , , ,

Moon over Citizens Bank Park 2

Moon over Citizens Bank Park 2

Posted on April 19, 2008 Leave a Comment
Tagged with: , , , , , , ,

The Philly Phanatic

The Philly Phanatic

Posted on April 19, 2008 Leave a Comment
Tagged with: , , , , , , , , ,

Ripped Jeans

Ripped Jeans

Posted on April 17, 2008 Leave a Comment
Tagged with: ,

Bird in Broken Window, Bethlehem Steel, Pennsylvania

Bird in Broken Window, Bethlehem Steel, Pennsylvania

Posted on April 17, 2008 Leave a Comment
Tagged with: , , , , ,

Bethlehem Sewer Cover

Bethlehem Sewer Cover

Posted on April 17, 2008 Leave a Comment
Tagged with: , , , ,

Old Books, Linderman Library, Lehigh University

Old Books, Linderman Library, Lehigh University

I really love the old books at Linderman, I’ll have to go back and take more shots some time.

Posted on April 17, 2008 Leave a Comment
Tagged with: , , , , , , ,

Cleaning Up User Submitted Data

A little while back, I complained about WordPress’ handling of URLs without “http://”. While it turns out WP actually handles these correctly, it brings up the question on how to handle a user’s inputted data. It’s always important to format or sanitize incoming data, and for items like URLs, which have a well-defined format, it’s really easy to do. Here’s how to do it in Rails.

One of the great things about Ruby is the way it treats just about anything as a method, so if I call link.url = "http://website.com", it’s actually calling the method Link#url= with the parameter of “http://website.com”. So, to intercept incoming data, I just overwrite the default url= method in my Link model:

class Link < ActiveRecord
  def url=(new_url)
    if new_url[0..6] != 'http://'
      new_url = 'http://' + new_url
    end

    super(new_url)
  end
end

So, now, when I set the url, it’s automatically formatted correctly. Some may advocate putting something like this in a before_save callback, but personally, I like to make sure the data is always correct, even when it hasn’t yet been saved.

Posted on April 15, 2008 Leave a Comment
Tagged with: , ,

Sculpture outside Zoellner Center, Lehigh University

Sculpture outside Zoellner Center, Lehigh University

Posted on April 15, 2008 Leave a Comment
Tagged with: , , , , ,

Sculpture outside Maginnes Hall, Lehigh University

Sculpture outside Maginnes Hall, Lehigh University

Posted on April 15, 2008 Leave a Comment
Tagged with: , ,

Construction Workers Squared Circle

Construction Workers Squared Circle

Posted on April 15, 2008 Leave a Comment
Tagged with: , , , , ,