Posts Tagged ‘programming’

Respect your users — give them a Beta-version.

Thursday, November 20th, 2008

I’m a big fan of release early and release often.  I’ve seen lots of software projects never make it out the door after thousands of dollars spent.  One thing they had in common:  they get caught up in new ideas, new fixes, and new deadlines.

But that’s the old development style.  Now that “beta” is a mainstream word (see screenshot), there are several good reasons for just putting the feature out there and slapping a beta label on it:

  • Google does it.  This actually implies several good reasons for doing it as well — it’s the only way to move quickly in this age of fast software development.  Also, Google is helping educate people about the meaning of “beta”.
  • “Beta” saves paragraphs of extra text — “This is still under development, blah blah blah …”
  • “Beta” shows that you respect your users — “This isn’t totally done yet, but we thought you’d want to give it a try.  We know you won’t hurt yourself.”

Anyone else want single sign-on between Rails and Wordpress, Beast, etc. ?

Saturday, November 1st, 2008

So I found that I keep wanting to integrate various Open Source applications into my Rails apps.  But when I search around to see who’s done that, I don’t find many success stories.

I decided to give the problem a shot, and I think I’ve actually solved it; I’ve created a framework along with Rails and Wordpress plugins that enable transparent single sign-on between them.

The basic idea is that the Rails app stays in control of logins and logouts.  The other applications connect via a web service API to provide the single sign-on function. Here are a couple of screen shots of the Wordpress plugin in the dashboard. 

I got the idea from thinking about the how one of the LDAP plugins functions in Wordpress — it connects to LDAP to perform the authentication, and creates a corresponding Wordpress user on the fly if necessary.

Here’s the Integration_API home page with links to the downloads.

Retrieving the height and width attributes of image thumbnails in Rails with attachment_fu

Wednesday, October 8th, 2008

The problem:

All of the examples I could find of how to display images with attachment_fu in Rails look like this:

image_tag(my_photo.public_filename(:small))

I programmed a complete website with this kind of code before I realized that I really need to include height and width attributes in my image tags.  The attachment object has height and width attributes… but in the example above, where I’m displaying the :small thumbnail of an image, I couldn’t find a way, via the API, to retrieve the small image version in order to query its height and width.

How images are used on Green Fabric

How I display images on Green Fabric

If there’s something obvious I’ve missed, please let me know!  At any rate, here’s an example page from Green Fabric, the site where I’m doing this.  Obviously, with this many images, having the height and width is critical.  And I’ve seen a huge difference in the perceived and actual page loading times after making my change.

My solution:

I’m new to Ruby, so I’m sure there’s a much smoother way of doing this, but here’s what I’ve written.  First, my new view template code to display the image in the example above would look like this:

photo_tag(my_photo, "small")

And the tag will include the correct height and width attributes.  Now comes the part where it’s clear that I’m not a Ruby expert.  I’m sure I could have done this by somehow mixing in new code into the attachment_fu library… but I don’t know how to do that.  So I created a couple of helper methods, which is what photo_tag is.  This code is from application_helper.rb:

  def thumbnail_for(full_size_image, thumbnail_name)
    full_size_image.thumbnails.each do |i|
      return i if i['thumbnail'] == thumbnail_name
    end

    return nil
  end

  def photo_tag(photo, thumbnail_name=nil, css_class=nil)
    if thumbnail_name.nil?
      image = photo
    else
      image = thumbnail_for(photo, thumbnail_name)
    end

    if css_class.nil?
      return image_tag(image.public_filename, :size=>image.image_size)
    else
      return image_tag(image.public_filename, :size=>image.image_size, :class=>css_class)
    end
  end