Skip to content

Instantly share code, notes, and snippets.

@gusrub
Created March 4, 2018 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gusrub/8bec878b0c24034e74763a522f0ad499 to your computer and use it in GitHub Desktop.
Save gusrub/8bec878b0c24034e74763a522f0ad499 to your computer and use it in GitHub Desktop.
MVC model 2
class User < ApplicationRecord
validates :first_name, presence: true
validates :last_name, presence: true
validates :email, presence: true
validates :token, presence: true
before_create :generate_token
after_create :send_welcome_email
private
def generate_token
uri = URI("https://example.com/#{email}")
response = Net::HTTP.get_response(uri)
if response.code == '200'
self.token = JSON.parse(response.body)[:token]
end
end
def send_welcome_email
UserMailer.welcome_message(self).deliver
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment