Created
September 18, 2009 04:55
-
-
Save notahat/188883 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
# This is my home-grown solution for implementing the model end of | |
# a multi-step form in Rails. | |
# | |
# There's a step attribute on the model, and the after_step method | |
# lets me limit validations to only occur after a particular step. | |
# | |
# I have to be careful in the controller to make sure the right | |
# attributes are set at each step, and that the step attribute can't | |
# be hacked. | |
class Signup < ActiveRecord::Base | |
def self.after_step(n, &block) | |
with_options(:if => lambda {|signup| signup.step >= n }) do |signup| | |
signup.instance_eval(&block) | |
end | |
end | |
after_step(1) do | |
validates_presence_of :name, :email_address, :mobile_phone | |
end | |
after_step(2) do | |
validates_presence_of :username, :password | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment