Zeitwerk causing issues while loading passwords_controller.rb file

Zeitwerk causing issues while loading passwords_controller.rb file

Hey everyone, if i may get a little help, i have recently added a file under controller section of my webapp, and from that time this is causing some issues as such :

/Railsapp/scheduled_tweets_flash# ^C
/Railsapp/scheduled_tweets_flash# rails s 
=> Booting Puma
=> Rails 7.0.7 application starting in development
=> Run `bin/rails server --help` for more startup options
Exiting
/root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader/helpers.rb:171:in `rescue in cname_for': wrong constant name PasswordsController  inferred by Module from file (Zeitwerk::NameError)

  /mnt/c/bckp/Railsapp/scheduled_tweets_flash/app/controllers/passwords_controller .rb

Possible ways to address this:

  * Tell Zeitwerk to ignore this particular file.
  * Tell Zeitwerk to ignore one of its parent directories.
  * Rename the file to comply with the naming conventions.
  * Modify the inflector to handle this case.


      raise Zeitwerk::NameError.new(<<~MESSAGE, error.name)
      ^^^^^
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader/helpers.rb:166:in `cname_for'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader.rb:414:in `block in set_autoloads_in_dir'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader/helpers.rb:40:in `block in ls'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader/helpers.rb:25:in `each'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader/helpers.rb:25:in `ls'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader.rb:411:in `set_autoloads_in_dir'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader.rb:124:in `block (2 levels) in setup'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader.rb:123:in `each'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader.rb:123:in `block in setup'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader.rb:120:in `synchronize'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader.rb:120:in `setup'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/application/finisher.rb:40:in `block in <module:Finisher>'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/initializable.rb:32:in `instance_exec'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/initializable.rb:32:in `run'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/initializable.rb:61:in `block in run_initializers'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:228:in `block in tsort_each'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:431:in `each_strongly_connected_component_from'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:349:in `block in each_strongly_connected_component'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:347:in `each'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:347:in `call'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:347:in `each_strongly_connected_component'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:226:in `tsort_each'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:205:in `tsort_each'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/initializable.rb:60:in `run_initializers'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/application.rb:372:in `initialize!'
        from /mnt/c/bckp/Railsapp/scheduled_tweets_flash/config/environment.rb:5:in `<main>'
        from config.ru:3:in `require_relative'
        from config.ru:3:in `block in <main>'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-2.2.8/lib/rack/builder.rb:116:in `eval'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-2.2.8/lib/rack/builder.rb:116:in `new_from_string'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-2.2.8/lib/rack/builder.rb:105:in `load_file'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-2.2.8/lib/rack/builder.rb:66:in `parse_file'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-2.2.8/lib/rack/server.rb:349:in `build_app_and_options_from_config'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-2.2.8/lib/rack/server.rb:249:in `app'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-2.2.8/lib/rack/server.rb:422:in `wrapped_app'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/commands/server/server_command.rb:76:in `log_to_stdout'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/commands/server/server_command.rb:36:in `start'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/commands/server/server_command.rb:143:in `block in perform'
        from <internal:kernel>:90:in `tap'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/commands/server/server_command.rb:134:in `perform'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/command.rb:27:in `run'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/invocation.rb:127:in `invoke_command'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor.rb:392:in `dispatch'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/command/base.rb:87:in `perform'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/command.rb:48:in `invoke'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/commands.rb:18:in `<main>'
        from <internal:/root/.asdf/installs/ruby/3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
        from <internal:/root/.asdf/installs/ruby/3.2.2/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in `require'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from bin/rails:4:in `<main>'
/root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader/helpers.rb:167:in `const_defined?': wrong constant name PasswordsController  (NameError)

      CNAME_VALIDATOR.const_defined?(cname, false)
                     ^^^^^^^^^^^^^^^
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader/helpers.rb:167:in `cname_for'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader.rb:414:in `block in set_autoloads_in_dir'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader/helpers.rb:40:in `block in ls'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader/helpers.rb:25:in `each'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader/helpers.rb:25:in `ls'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader.rb:411:in `set_autoloads_in_dir'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader.rb:124:in `block (2 levels) in setup'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader.rb:123:in `each'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader.rb:123:in `block in setup'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader.rb:120:in `synchronize'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader.rb:120:in `setup'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/application/finisher.rb:40:in `block in <module:Finisher>'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/initializable.rb:32:in `instance_exec'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/initializable.rb:32:in `run'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/initializable.rb:61:in `block in run_initializers'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:228:in `block in tsort_each'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:431:in `each_strongly_connected_component_from'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:349:in `block in each_strongly_connected_component'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:347:in `each'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:347:in `call'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:347:in `each_strongly_connected_component'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:226:in `tsort_each'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/tsort.rb:205:in `tsort_each'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/initializable.rb:60:in `run_initializers'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.7/lib/rails/application.rb:372:in `initialize!'
        from /mnt/c/bckp/Railsapp/scheduled_tweets_flash/config/environment.rb:5:in `<main>'
        from config.ru:3:in `require_relative'
        from config.ru:3:in `block in <main>'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-2.2.8/lib/rack/builder.rb:116:in `eval'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-2.2.8/lib/rack/builder.rb:116:in `new_from_string'
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rack-2.2.8/lib/rack/builder.rb:105:in `load_file'
root@DESKTOP-MI3GRH3:/mnt/c/bckp/Railsapp/scheduled_tweets_flash# rails s
=> Booting Puma
=> Rails 7.0.7 application starting in development       
=> Run `bin/rails server --help` for more startup options
Exiting
/root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.11/lib/zeitwerk/loader/helpers.rb:171:in `rescue in cname_for': wrong constant name PasswordsController  inferred by Module from file (Zeitwerk::NameError)

  /mnt/c/bckp/Railsapp/scheduled_tweets_flash/app/controllers/passwords_controller .rb

Possible ways to address this:

  * Tell Zeitwerk to ignore this particular file.
  * Tell Zeitwerk to ignore one of its parent directories.
  * Rename the file to comply with the naming conventions.
  * Modify the inflector to handle this case.


      raise Zeitwerk::NameError.new(<<~MESSAGE, error.name)
      ^^^^^
        from /root/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeit

What is the name of the class in the passwords_controller.rb file?

Zeitwerk expects the filename to map to the class name within the file in a conventional manner.

  • app/controllers/passwords_controller.rb → PasswordsController
  • app/controllers/my_namespace/passwords_controller.rb → MyNamespace::PasswordsController

You need to follow the instructions and change either the file name or the class name to this convention. You can read more in the guide.


Here is my passwords_controller.r,b can you spot any mistakes : 


class PasswordsController < ApplicationController
  # Ensure that the user is logged in before accessing the edit and update actions.
  before_action :require_user_logged_in!

  def edit
    # The edit action typically renders a form to update the password,
    # so there's no need for additional comments here.
  end

  def update
    if Current.user.update(password_params)
      redirect_to root_path, notice: "Password updated successfully!"
    else
      render :edit, alert: "Something went wrong, please try again."
    end
  end

  private

  # Define a private method to permit the password and password_confirmation parameters.
  # This method is used by the update action to filter the allowed parameters.
  def password_params
    params.require(:user).permit(:password, :password_confirmation)
  end
end

There’s a redundant space character in the file name, just before .rb.

1 Like