Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restricting access to a Rails Engine's routes...constraints not working

I've got a Rails Engine in my app. Here's its hook into my routes.rb file:

Mercury::Engine.routes

I'm trying to restrict access to the URLs provided by the engine so I tried using constraints:

class EditorRestrictor
  def self.matches?(request)
    false
  end
end

constraints EditorRestrictor do
  Mercury::Engine.routes
end

But the engine's routes are still accessible. I restarted my app just in case but it didn't matter. Any ideas?

like image 235
Rob Cameron Avatar asked Nov 05 '22 09:11

Rob Cameron


1 Answers

Typically you'd mount routes for your engines like this:

Rails.application.routes.draw do
    mount Mercury::Engine => '/mercury'

    # If you wanted routes mounted on root
    # mount Mercury::Engine => '/'    
end

So if you want to add constraints, you could say:

Rails.application.routes.draw do
    mount Mercury::Engine => '/mercury', constraints: {}
end
like image 173
Darren Nix Avatar answered Nov 14 '22 23:11

Darren Nix