I am displaying users cpm based on their submitted form. It all works until I am creating a new user who doesn’t have such cpm yet. Then I get an error. I understand that I need to use case in which I check either there is a cpm or not, if not I return a link to needed form. I was wondering how to do it, as I am not sure what I should write in such case.
My page_controller:
def index(conn, _params, current_user) do
user = current_user.id
user_pps = Cpm.list_user_pp(current_user)
user_pp = Cpm.get_user_pp!(current_user, user)
user_bmr = Bmr.bmr_for_user(user_pp)
user_cpm = Float.floor(Bmr.cpm_for_user(user_pp, user_bmr))
case user_cpm do
{:ok} -> returns first cpm
{:error} -> returns a link to a form
render(conn, "index.html", user: user, userp_pps: user_pps, user_cpm: user_cpm)
What if I don’t want to redirect from start? I want to keep a user on the front page so he has access to different things, only if he wants to he can click a button to redirect to my form