Skip to content

Instantly share code, notes, and snippets.

@gusrub gusrub/mvc_controller_2.rb Secret
Last active Mar 4, 2018

Embed
What would you like to do?
MVC controller 2
class UsersController < ApplicationController
def create
if params[:token].blank?
@user.token = generate_token
end
if @user.save
UserMailer.welcome_message(@user).deliver if params[:send_email]
render json: @user, status: 200
else
render json @user.errors, status: 400
end
end
private
def generate_token
uri = URI("https://example.com/#{@user.email}")
response = Net::HTTP.get_response(uri)
if response.code == '200'
return JSON.parse(response.body)[:token]
end
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.