Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.