-
-
Save gusrub/ebf394e5a3525afd65e98205afb5c17d to your computer and use it in GitHub Desktop.
MVC controller 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 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