Search code examples
ruby-on-railsrubyruby-on-rails-4urlsubdomain

Rails 4: Limit URL's to the main domain


Something I've noticed using subdomains with Rails is, that every controller action, which is not specifically assigned to a subdomain can get accessed via every subdomain.


For example:

get "/hello" => "welcome#hello"

is not just available through "domain/hello" but also through "subdomain.domain/hello"

Can I limit this controller action to just be accessible for "domain/hello"?


Solution

  • get "hello", to: "welcome#hello", constraints: { subdomain: "" }