Last active
July 29, 2017 04:28
-
-
Save fj/8243261 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# In a context somewhere, we'd like to do this: | |
u = User.new | |
u.extend Passworded | |
# Unfortunately, this doesn't work: | |
module Passworded | |
include ActiveModel::Model # Can't do this because ActiveModel::Model wants to be included | |
# on classes, not modules. | |
# Also can't remove it, because if you do then your validation | |
# methods aren't defined. | |
attr_accessor :password | |
attr_accessor :password_confirmation | |
validates :password, :presence => true, :confirmation => true | |
validates :password_confirmation, :presence => true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@saturnflyer Yeah, I need to run "expert user" vs. "non-expert user" validations on a
OptionsContract
model. Some validations always apply (those go on the model), some apply when a non-expert user wants to make changes, and some apply when an expert user wants to make changes.I'll give this a shot!