So I'm running into some issues that I'm not aware of how to solve when I'm improving my code.
Currently in my controller#show I have this ugly piece of code:
def show
@room = Room.find(params[:id])
if user_signed_in?
gon.push(
session_id: @room.session_id,
api_key: 453,
token: current_user.tokens.last.token
)
elsif customer_signed_in?
gon.push(
session_id: @room.session_id,
api_key: 453,
token: current_customer.tokens.last.token,
customer_id: current_customer.id
)
elsif @room.price == 0.0
@token = OT.generate_token @room.session_id
gon.push(
session_id: @room.session_id,
api_key: 453,
token: @token
)
else
@customer = Customer.new
end
end
now I would like to move this into the rooms model. The issue that I'm having is that I'm having an if else based on if it's a user, customer or neither. How would I go about moving this into a model and still be able to validate this?