Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined local variable or method config for main #54

Closed
bendangelo opened this issue Sep 27, 2024 · 4 comments
Closed

undefined local variable or method config for main #54

bendangelo opened this issue Sep 27, 2024 · 4 comments

Comments

@bendangelo
Copy link

Not sure what's happening. I already had devise setup with a user model.

Running: rails generate trestle:auth:install User

/home/bendangelo/Projects/englishfox_web/config/initializers/trestle.rb:141:in `<main>': undefined local variable or method `config' for main (NameError)

  config.auth.user_class = -> { User }
  ^^^^^^
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/engine.rb:689:in `load'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/engine.rb:689:in `block in load_config_initializer'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/activesupport-7.2.1/lib/active_support/notifications.rb:212:in `instrument'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/engine.rb:688:in `load_config_initializer'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/engine.rb:642:in `block (2 levels) in <class:Engine>'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/engine.rb:641:in `each'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/engine.rb:641:in `block in <class:Engine>'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/initializable.rb:32:in `instance_exec'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/initializable.rb:32:in `run'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/initializable.rb:61:in `block in run_initializers'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/tsort.rb:231:in `block in tsort_each'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/tsort.rb:353:in `block (2 levels) in each_strongly_connected_component'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/tsort.rb:425:in `block (2 levels) in each_strongly_connected_component_from'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/tsort.rb:434:in `each_strongly_connected_component_from'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/tsort.rb:424:in `block in each_strongly_connected_component_from'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/initializable.rb:50:in `each'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/initializable.rb:50:in `tsort_each_child'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/tsort.rb:418:in `call'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/tsort.rb:418:in `each_strongly_connected_component_from'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/tsort.rb:352:in `block in each_strongly_connected_component'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/tsort.rb:350:in `each'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/tsort.rb:350:in `call'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/tsort.rb:350:in `each_strongly_connected_component'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/tsort.rb:229:in `tsort_each'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/3.3.0/tsort.rb:208:in `tsort_each'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/initializable.rb:60:in `run_initializers'
        from /home/bendangelo/.asdf/installs/ruby/3.3.5/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/application.rb:435:in `initialize!'

@bendangelo
Copy link
Author

I see the error. The end was put too early in the trestle initializer.

  end

  # == Authentication Options
  #
  # Specify the user class to be used by trestle-auth.
  #
  config.auth.user_class = -> { User }

@spohlenz
Copy link
Member

Just checking whether this was caused by one of the install generators, or via local editing? If the latter, I'll go ahead and close this issue.

@bendangelo
Copy link
Author

It was caused by the install generators. I believe the second install does a bad insert.

@spohlenz
Copy link
Member

I was able to reproduce this when there was an extra unindented end prior to the final closing end.

I've fixed this in #56 to ensure the trestle-auth config is inserted just before the final occurrence of end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants