Form_with on a model loses its naming convention after the call on render method

I am pretty sure that’s not expected behaviour but I am unsure how to approach the problem. So let’s start with introducing two important actors in this scenerio: LoginsController

class LoginsController < ApplicationController
  layout "application"
  def new
    @user = User.new
  end

  def create
    @user = User.find_by(name: user_params[:name])&.
    authenticate(user_params[:password])
    unless @user.nil? || @user == false
      reset_session
      session[:current_user_id] = @user.id
      flash[:notice] = "Successful login!"
      redirect_to root_url
    else
      flash[:alert] = "Wrong name or password!"
      render :new, status: :unauthorized
    end
  end

  def destroy
    session.delete(:current_user_id)
    @_current_user = nil
    redirect_to root_url, status: :see_other
  end

  private
    def user_params
      params.require(:user).permit(:name, :password)
    end
end

and a login partial

<%= form_with url: login_url, model: user do |form| %>
    <div class="form-content">
        <h1>Login panel</h1>
        <div class="form-column-container">
            <div class="form-column-left">
                <%= form.label :name %>
                <%= form.label :password %>
            </div>

            <div class="form-column-right">
                <%= form.text_field :name %>
                <%= form.password_field :password %>
            </div>
        </div>

        <% if flash[:alert] %>
            <div class="alert"><%= flash[:alert] %></div>
        <% end %>
            
        <%= form.submit "Log in"%>
    </div>
<% end %>

The partial is of course rendered in a new action of LoginsController. On a fresh visit, every input seems to have properly named attributes.

<div class="form-column-right">
      <input type="text" name="user[name]" id="user_name" />
      <input type="password" name="user[password]" id="user_password" />
</div>

The problem raises when invalid credentials are passed out - when render method gets called, the form somehow loses the naming convention it gets from a model.

<div class="form-column-right">
      <input type="text" name="name" id="name" />
      <input type="password" name="password" id="password" />
</div>

Now, this behaviour seem to only happen with this specific form and not on any others I use and it only happens when render method in LoginsController gets called - otherwise, no such issue occurs. What could be the cause of that?

Okay, managed to find the cause - in the end it was a fault of @user returning nil or false that carried through render, since render does not call @user = User.new. Fixed the problem by passing User.new instead of an instance variable. Sometimes just a nap can make you realise how simple the solution is. Leaving this topic in case someone would encounter the same issue and didn’t figure out the possible cause of the problem.