-
-
Save joho/188886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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