Skip to content

Instantly share code, notes, and snippets.

@steveklebanoff
Created November 19, 2014 04:05
Show Gist options
  • Save steveklebanoff/7f41e2eea47dcb81567d to your computer and use it in GitHub Desktop.
Save steveklebanoff/7f41e2eea47dcb81567d to your computer and use it in GitHub Desktop.
Devise Simple Invitation Code
<% # 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>
# 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
# 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