Created
March 4, 2018 02:23
-
-
Save gusrub/8bec878b0c24034e74763a522f0ad499 to your computer and use it in GitHub Desktop.
MVC model 2
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
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