Skip to content

Error when rendering in a before_action hook #238

@christopher-b

Description

@christopher-b

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions