Skip to content

Instantly share code, notes, and snippets.

@sergiomaia
Created December 14, 2016 13:32
Show Gist options
  • Save sergiomaia/311d8979d8e8aa6305a3e1a3ce66f5dd to your computer and use it in GitHub Desktop.
Save sergiomaia/311d8979d8e8aa6305a3e1a3ce66f5dd to your computer and use it in GitHub Desktop.
# 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