Ringo Blancke
Ringo Blancke

Reputation: 2444

Rails routing: cannot differentiate static and dynamic routes

I'm trying to create custom URLs for my site's users:

www.mysite.com/user1

If I set the routing rule to be this:

match ':id' => "user#view", :as => :user

Then it works great! I can access www.mysite.com/user1 and it will pull up the page for user1.

However, that breaks my about page, which is at www.mysite.com/about . The error I get here is: "Couldn't find User with id=about"

Any idea how I can fix this problem? Thanks! As an aside - I'm using friendlyid to generate the human readable slugs.

Ringo

Upvotes: 0

Views: 111

Answers (1)

Ryan Bigg
Ryan Bigg

Reputation: 107728

Is the about page a static file located at public/about.html? If so, then Rails will match this first and fall back to the router if it can't find the file.

If it's a route instead, then your match :id route should be beneath the one for about, so that about is matched first.

Upvotes: 3

Related Questions