Skip to content

Instantly share code, notes, and snippets.

@joho
Forked from notahat/signup.rb
Created September 18, 2009 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joho/188886 to your computer and use it in GitHub Desktop.
Save joho/188886 to your computer and use it in GitHub Desktop.
class Signup < ActiveRecord::Base
def self.at_step(n, &block)
@@step_specific_code ||= {}
@@step_specific_code[n] = block
end
at_step(1) do
validates_presence_of :name, :email_address, :mobile_phone
attr_accessible :name, :email_address, :mobile_phone
end
at_step(2) do
validates_presence_of :username, :password
attr_accessible :username, :password
end
def advance_step
self.step += 1
instance_eval @@step_specific_code[self.step] if @@step_specific_code[self.step]
yield self
end
end
class SignupController < ActionController::Base
def step_two
@signup = Signup.find(params[:id])
@signup.advance_step do |signup|
signup.attributes = params[:signup]
signup.save!
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment