Hi,
I am calculating users score dynamically. The result i am rendering on the main page. However, the moment I create a new user I get an error - expected at least one result but got none in query
. Therefor I guess I should use an if
statement, however I am not sure what I am doing wrong. Any suggestions?
controller
def index(conn, _params, current_user) do
...
user_score = Float.floor(Exercise.score_for_user(user_id, user_exercise)
render(conn, "index.html", user_score: user_score)
template
<%= if @current_user do %>
<%= if @user_score do %>
<h2>User Score: <br> <%= @user_score %></h2>
<% end %>
...
<% end %>