简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM