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

Mounting the engine with a route constraint #92

Open
olimart opened this issue Mar 7, 2024 · 1 comment
Open

Mounting the engine with a route constraint #92

olimart opened this issue Mar 7, 2024 · 1 comment

Comments

@olimart
Copy link

olimart commented Mar 7, 2024

Hey,

Albeit the mention of setting the base controller, I was trying to define a contraint while mounting the engine.
mount MissionControl::Jobs::Engine, at: "jobs", constraints: AdminConstraint.new

class AdminConstraint
  def matches?(request)
    return unless request.session[:user_id]
    User.find(request.session[:user_id])&.admin?
  end
end

which fails because <ActionDispatch::Request::Session:0x72ba0 not yet loaded>

I don't know if it's a limit of Rails engine (it used to work with Sidekiq dashboard though) or if there is some loading logic to change to make it work. Is that something that can be envisioned? Thanks

@gjtorikian
Copy link

Unsure if this'll be helpful in your situation, but for a constraint I write mine as:

  constraints ->(request) { StaffController.staff_request?(request) } do
    mount MissionControl::Jobs::Engine, at: "staff/jobs"
  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