I have a user who can have 0 for many.
I want to show:
- a new business page if the user has not created any enterprises or
- business show page if they have 1 business or
- business index page if more than one business exists.
Where should I put this logic? in the view or in the controller?
for example, in the controller:
if !@user.businesses.any?
redirect_to new_user_business_path(@user)
elsif @user.businesses.count == 1
redirect_to business_path(@user.businesses.first)
elsif @user.businesses.count > 1
redirect_to businesses_path(@user)
end
or in the view:
<% if !@user.businesses.any? %>
<%= render partial 'no_businesses' %>
etc.
It doesn't look like in the view, but I thought it would be nice to ask for the best practice.
source
share