Reputation: 19723
Wondering why my routes don't work with what was described in the rails guide. http://admin.foo.dev:3000/
takes me to the root_path
, and not admin::pages#home
.
The first approach works though. Which was taken from Railscast.
# WORKS!
match '', to: 'pages#home', constraints: lambda { |r| r.subdomain.present? && r.subdomain != 'www' }
# does NOT work!
namespace :admin do
constraints :subdomain => "admin" do
root :to => 'pages#home'
end
end
I have everything setup in /etc/hosts
. It looks like:
127.0.0.1 localhost
127.0.0.1 api.foo.dev admin.foo.dev foo.dev www.foo.dev
Upvotes: 0
Views: 603
Reputation: 16064
Since your route is inside a namespace, the correct page that would take you to admin::pages#home
would be http://admin.foo.dev:3000/admin/
. Remove the namespace to connect correctly.
In general, if you're ever confused what routes are being generated and how to get to them, use rake routes
. And for more on namespacing routes (and why you might not want to use namespaces in situations like this), check out the Rails routing guide.
Upvotes: 2