So I am using the Vanity gem that handles all params[:vname] in my URLs and redirects to the right place for most vnames.
But I just added authentication via Omnipopulus – https://github.com/icelab/omnipopulus – and it requires me to go to `mydomain.com/login’.
But when I do that it sends it to my Vanities controller. Here is the log of that request:
Started GET "/login" for 127.0.0.1 at 2011-09-18 16:39:15 -0500
Processing by VanitiesController#show as HTML
Parameters: {"vname"=>"login"}
Vanity Load (0.1ms) SELECT "vanities".* FROM "vanities" WHERE "vanities"."name" = 'login' LIMIT 1
Rendered public/404.html within layouts/application (0.0ms)
Completed 404 Not Found in 13ms (Views: 11.5ms | ActiveRecord: 0.3ms)
What the Vanities controller does, is when it gets a URL as mydomain.com/vname it checks to see if a vname record exists for the value in the params (which is typically a username). If it finds one, it redirects to the show action of that user. But given that login is not a user nor username, it shouldn’t be handling the routing for that keyword.
How do I add an exception?
This is the route for the Vanities controller:
controller :vanities do
match ':vname' => :show, :via => :get, :constraints => {:vname => /@?[A-Za-z0-9\-\+]+/}, :as => :vanity
end
I’ve never used (or even heard of) this gem before, but looking at its source code, see:
https://github.com/icelab/omnipopulus/blob/master/config/routes.rb
This appears to install itself as a Rails engine, and therefore isn’t really in your routes.rb file. I’m thinking there may be a few things to test here.
First of all, realize that vanities’ routes MUST be the ABSOLUTE DEAD LAST in your routes file. What’s happening here is that when you call /login, the vanities routing is happening before your authentication gem’s routing is being called. Normally I’d just say, “move the vanities routes to the last in routes.rb”, but given that omnipopulous injects its routes based on its engine, that may not be enough.
I see two possible ways of solving this:
I see #2 as an ugly hack, so I really hope #1 works first (depends on load order for gems with bundler, which I think will go top-down, but I don’t have any proof of that so far).