Search code examples
ruby-on-railsrubyroutesrails-activestorageruby-on-rails-6

Rails 6: Catch all route constraint not working


I placed a catch all route at the bottom of my route file. Annoyingly, Active Storage requests are also directed to the same action. I don't want that.

I have read this on SO and this issue on Github that suggest adding a constraint to the route.

Rails.application.routes.draw do
#...
  get "/*slug" => "profiles#show",
      param: :slug,
      as: "profile",
      contraints: lambda { |req|
        req.path.exclude? "rails/active_storage"
      }
end

However, this isn't working for me. ActiveStorage requests are still going to profiles#show. What is wrong with my constraint? Have I missed anything obvious?


Solution

  • You have a typo.

    It should be constraints: instead of contraints:.