We've moved discussions to Discord

Removing the name field from users fails to create accounts on sign up

Joshua LeBlanc
Kind of a weird problem, and I can't really figure out why it's happening.

If you take the base installation, and remove the following lines:

views/devise/registrations/new.html.erb#27-31
models/user.rb#70-72
Then create a new user, the sign up will succeed, and resulting page will rail to render with

ActionView::Template::Error (undefined method `id' for nil:NilClass):
    1: <%= tag.div data: { controller: "notifications", notifications_account_id: current_account.id }, class: "z-10 mr-4 inline-flex items-center align-middle leading-none rounded no-underline text-gray-700 hover:text-gray-800 hover:bg-white" do %>
    2:   <div class="relative" data-controller="dropdown">
    3:
    4:     <%# Marks all notifications as read when menu opens by default. Remove the notifications Stimulus actions to disable this. %>

I can confirm that after signing up, there is nothing in the accounts, or account_users tables.

I also tried removing the :name validation from account.rb, and removing the :name params in application_controller.rb, to no avail.

Joshua LeBlanc
In true rubber-duck debugging fashion, typing this out caused me to find the issue. 

In case someone else comes here looking for the same answers, the following lines have to be changed (or at least, these are the lines I changed).

# models/concerns/user_accounts.rb

  def create_default_account
-   # Invited users don't have a name immediately, so we will run this method twice for them
-   # once on create where no name is present and again on accepting the invitation
-   return unless name.present?
    return accounts.first if accounts.any?

-   account = accounts.new(owner: self, name: name, personal: Jumpstart.config.personal_accounts)
+   account = accounts.new(owner: self, personal: Jumpstart.config.personal_accounts)
    account.account_users.new(user: self, admin: true)
    account.save!
    account
  end

# models/account.rb
- validates :name, presence: true

# models/user.rb

- has_person_name

- include PgSearch::Model
- pg_search_scope :search_by_full_name, against: [:first_name, :last_name], using: {tsearch: {prefix: true}}

  # ActiveStorage Associations
  has_one_attached :avatar

  # Associations
  has_many :api_tokens, dependent: :destroy
  has_many :connected_accounts, dependent: :destroy
  has_many :notifications, as: :recipient, dependent: :destroy

  # We don't need users to confirm their email address on create,
  # just when they change it
  before_create :skip_confirmation!

- # Validations
- validates :name, presence: true

# views/devise/registrations/new.html.erb

-   <div class="form-group">
-     <%= f.label :name, "Full name" %>
-     <%= f.text_field :name, autofocus: true, autocomplete: "name", placeholder: true, class: "form-control" %>
-   </div>
Notifications
You’re not receiving notifications from this thread.