Designer needed

29 Mar 2007

This may come a surprise to you, but I’m terrible at design. So I ask you, the excellent and friendly community at large, for your assistance. I need some design help. I’m talking the whole enchilada, here: user interface / user experience, branding, etc. I need every aspect of design under the sun to help me launch CatchTheBest. So, if you have the skills, the time, and the interest, or you know someone who does, please get in touch.

Update:
Since I didn’t specify this originally, and since people have asked, yes, I am willing to pay for this work. I know good work isn’t free. :) Of course, since this is a bootstrap situation, I don’t have a huge budget, but I am fairly flexible on the timeframe.



Rails E-commerce Book Finished

10 Mar 2007

It took longer than I had planned, but today I wrapped up my book on building an e-commerce store with Ruby on Rails. For those who have already purchased the book, the email notifying you how to get the latest revision is on its way. For those who haven’t, go buy it! :)

Recent changes include some updates for the latest version of Rails, tips on implementing combination discounts, and a little additional information on processing refunds.

As always, feedback is welcome and appreciated.



Favorite Rails Plugins

5 Mar 2007

Earlier this morning I wrote about using OpenID with the Acts as Authenticated plugin for the Rails plugin directory. Were you wondering why you’d want to have a login at the plugin directory? :)

Over the weekend I added the ability to add plugins to your own list of favorite plugins. While viewing any plugin at the site, you can click the “Add to favorites” link to add it to your list. Now it’s easy to keep track of the plugins you use on a regular basis — which is especially handy when starting new projects.

Thanks to Michael Trier and Mike Schwab for the suggestion. Stay tuned… I’ll be adding another feature soon that will make your list of favorite plugins extra handy.



Rails, OpenID, and Acts as Authenticated

5 Mar 2007

This weekend I added OpenID to a Rails application for the first time, and this blog post describes the steps I took to integrate OpenID with Acts as Authenticated for account creation and access.

First I installed David’s OpenID Rails plugin (as discussed at David’s blog) into my application which was already using AAA to handle account creations and logins. I then created the following migration to add the OpenID identity URL to my user model:

class AddOpenId < ActiveRecord::Migration
  def self.up
    add_column :users, :identity_url, :string
  end

  def self.down
    remove_column :users, :identity_url
  end
end

And I changed the User model to allow accounts to be created either with login/email/password or with only an identity url (only changed lines are listed):

class User < ActiveRecord::Base
  validates_presence_of :login,
    :email, :if => :not_openid?
  validates_length_of :login,
    :within => 3..40, :if => :not_openid?
  validates_length_of :email,
    :within => 3..100, :if => :not_openid?
  validates_uniqueness_of :login, :email, :salt, :allow_nil => true

  def password_required?
    not_openid? && (crypted_password.blank? or not password.blank?)
  end
 
  def not_openid?
    identity_url.blank?
  end
end

This allows me to create User records without the usual required fields as long as the user created the account via an OpenID login.

And finally, the controller changes:

class AccountController < ApplicationController
  def login
    if using_open_id?
      open_id_authentication
    elsif params[:login]
      password_authentication(params[:login], params[:password])
    end
  end

  protected
 
    def password_authentication(login, password)
      if self.current_user = User.authenticate(params[:login], params[:password])
        successful_login
      else
        failed_login("Invalid login or password")
      end
    end
 
    def open_id_authentication
      authenticate_with_open_id do |result, identity_url|
        if result.successful?
          if self.current_user = User.find_or_create_by_identity_url(identity_url)
            successful_login
          else
            failed_login "Sorry, no user by that identity URL exists (#{identity_url})"
          end
        else
          failed_login result.message
        end
      end
    end

  private
 
    def successful_login
      redirect_back_or_default(index_url)
      flash[:notice] = "Logged in successfully"
    end

    def failed_login(message)
      redirect_to(:action => ‘login’)
      flash[:warning] = message
    end
end

That’s it! You can see it in action at the Rails plugin directory.

Update
I updated this code to match the plugin changes that were made between the time I installed the plugin and the time I posted this entry. :)

Update 2
I made another change to the code based on Geoff’s comment. Thanks, Geoff!