-
-
Save motoroller95/bb5bf6f01a7bf47fc52c2c8a57528668 to your computer and use it in GitHub Desktop.
create two classes with same interfaces
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
# User attributes name surname | |
class User < ApplicationRecord | |
# attributes :id, integer | |
# attributes :name, string | |
# attributes :email, string | |
def log! | |
Log.create!(...) | |
end | |
def create_gift! | |
true | |
end | |
end | |
class GuestUser | |
# your code here | |
end | |
class GiftsController < ApplicationController | |
def current_user | |
@current_user = begin | |
user = User.find_by(token: session[:token]) | |
user = GuestUser.new unless user | |
user | |
end | |
end | |
def index | |
current_user.log! | |
render json: Gift.where(user_id: current_user.id) | |
end | |
def create | |
current_user.log! | |
if current_user.create_gift! | |
render json: { success: true } | |
else | |
render json: { success: false } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment