if, elsif, else statements html erb beginner
An even cleaner approach would be to flatten the statement, handling the not logged-in condition first so you don't have to test it along with whether they have a booth:
<% if !logged_in? %>
// not logged in code
<% elsif has_booth?(current_user.id) %>
// logged in and has booth code
<% else %>
// logged in and does not have booth code
<% end %>
You could also have used unless logged_in?
, but the else and elsif don't make as much sense, semantically, with unless and therefore it doesn't read as clearly.
The problem is that your first condition is true, so it stops there. Your first condition:
<% if logged_in? %>
Even if they don't have a booth it will never reach the elsif because the first condition is true. You either need:
<% if logged_in? && has_booth?(current_user.id) %>
// code
<% elsif logged_in? && !has_booth?(current_user.id) %>
// code
<% else %>
// code
<% end %>
Or it might be a cleaner approach to separate them into two if/else:
<% if logged_in? %>
<% if has_booth?(current_user.id) %>
// code
<% else %>
// code
<% end %>
<% else %>
// code
<% end %>