Skip to content

Instantly share code, notes, and snippets.

@takkkun
Last active December 19, 2015 01:19
Show Gist options
  • Select an option

  • Save takkkun/5874607 to your computer and use it in GitHub Desktop.

Select an option

Save takkkun/5874607 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
attr_accessor :current_phase
def self.thereafter(phase)
-> do
current_phase.nil? or current_phase >= phase
end
end
validates :email, presence: true, if: thereafter(1)
validates :name, presence: true, if: thereafter(2)
end
class UsersController < ApplicationController
def first
user = User.new(params[:user].merge(current_phase: 1))
if user.valid?
#
else
#
end
end
def second
user = User.new(params[:user].merge(current_phase: 2))
#
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment