We've moved discussions to Discord

Teams / Accounts

Andrew Hodson
Can I change this
<% if @accounts.exists? %>
  <div>
    <%= link_to 'Create a Account', new_account_path, class: "btn btn-primary" %>
  </div>
<% end %>
to 
<% if @accounts.exists? %>
  <% if @accounts.count <= 1 %>
    <div>
      <%= link_to 'Create a Account', new_account_path, class: "btn btn-primary" %>
    </div>
  <% end %>
<% end %>

To limit account to 1 personal or 1 team type account?

Thanks!
Chris Oliver
Of course, you can. 👍

I would do this on the AccountsController as well to make sure it's not allowed in the controller, not just visually in the view.
Andrew Hodson
Awesome! done.

before_action :prevent_multiple_accounts, only: [:new]

def prevent_multpile_accounts
  accounts = current_user.accounts
  if accounts.count > 1
    redirect_to accounts_path(), alert: "You cannot have multiple accounts."
  end
end



Notifications
You’re not receiving notifications from this thread.