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

Error when rendering in a before_action hook #238

Open
christopher-b opened this issue Jan 21, 2025 · 0 comments
Open

Error when rendering in a before_action hook #238

christopher-b opened this issue Jan 21, 2025 · 0 comments

Comments

@christopher-b
Copy link
Contributor

christopher-b commented Jan 21, 2025

I'm encountering an error that seems to be related to custom authentication and short-circuit rendering:

ActionView::Template::Error (undefined method 'servers' for nil)
Information for cause: ActionView::Template::Error (undefined method 'servers' for nil):
     1: <% if application.servers.many? %>
     2:   <div class="server-selector navbar-item">
     3:     <div class="tabs is-toggle is-toggle-rounded is-small">
     4:       <ul>

app/lib/authentication.rb:20:in 'Authentication#require_login'

I am using a non-default base_controller_class, which has a before_action hook for authentication. It will render a login form if the user is not authenticated. Here is app/lib/authentication.rb:20:

render "sessions/new", status: :unauthorized unless authentication_context.logged_in?

I believe that the Mission Control layout is still being rendered, which is rendering the application selection partial, but application.servers has not been set.

I'm not sure about the best way to handle this. Is this something I should be overriding in my application, or should it be fixed in Mission Control itself? Perhaps the Mission Control layout should also be set in a before_action, so that the parent controller hooks run first, before the layout has been changed? Should the application being referenced in the partial be initialized in a different way?

I'm happy to contribute a PR but would like some guidance around the desired approach. Thanks.

@christopher-b christopher-b changed the title Error: "undefined method 'servers' for nil" when using non-default controller with authentication Error when rendering in a before_action hook Jan 21, 2025
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

1 participant