Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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