Created
December 14, 2016 13:32
-
-
Save sergiomaia/311d8979d8e8aa6305a3e1a3ce66f5dd 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
# app/forms/registration.rb | |
class Registration | |
include ActiveModel::Model | |
attr_accessor( | |
:company_name, | |
:email, | |
:first_name, | |
:last_name, | |
:terms_of_service | |
) | |
validates :company_name, presence: true | |
validates :email, presence: true, email: true | |
validates :first_name, presence: true | |
validates :last_name, presence: true | |
validates :terms_of_service, acceptance: true | |
def save | |
if valid? | |
persist! | |
true | |
else | |
false | |
end | |
end | |
private | |
def persist! | |
user = User.create!(email: email) | |
# ... | |
# ... | |
# ... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment