Created
November 19, 2014 04:05
-
-
Save steveklebanoff/7f41e2eea47dcb81567d to your computer and use it in GitHub Desktop.
Devise Simple Invitation Code
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 your custom app/views/users/registrations/new.html.erb %> | |
<div class='form-group'> | |
<%= f.label :invite_code %><br /> | |
<%= text_field_tag "user[invite_code]" %> | |
</div> |
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 app/controllers/users/registrations_controller.rb | |
before_action :permit_invite_code | |
def permit_invite_code | |
devise_parameter_sanitizer.for(:sign_up) << :invite_code | |
end |
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 app/models/user.rb | |
attr_accessor :invite_code | |
validate :invite_code_valid, :on => :create | |
def invite_code_valid | |
unless self.invite_code == "somecoolcode" | |
self.errors.add(:invite_code, "invalid. Ask Steve or try again.") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment