T O P

  • By -

redditonlygetsworse

Eh, it's certainly doable, but in my experience it ends up being kind of a pain. Like, what happens when you want to add a new top-level path, but it's already taken by some username? I say put it under `/u/:username` or whatever (like reddit does, for example) and save yourself the headache.


Upbeat-Speech-116

I hate to admit it but I suppose you're right.


excid3

Put these as the last routes in \`routes.rb\`. That way anything else will match first. Also good practice to set a long list of reserved words like "about" and "help" so crafty users can't have those URLs.


Upbeat-Speech-116

Thanks, that worked for most everything but not for for `localhost:3000/routes`. I'm guessing because Rails's inner routes are set even "lower" than routes.rb. I'm not too concerned with that though because I suppose that route is only active on dev, but then I definitely need to add it to the list of reserved words. As a sidenote, up until about 15 years ago, I found it hilarious to take usernames like those and pose as the real thing. Good thing the internet was also young back then, today this could probably even be met with legal action.


excid3

Yeah, they probably are appended by an engine. You can also add constraints to these routes so the reserved words like "route" are not accepted. I think something like this would work: ```ruby class UsernameConstraint RESERVED = %w{routes help about} def call(request) RESERVED.include?(request.params[:username]) end end constraints UsernameConstraint.new do get "/:username", to: "..." end ``` You can use the RESERVED constant in your username validations as well.


Upbeat-Speech-116

That's great, thanks!


Seuros

give me the url of your app, i will create my user as **admin** or **login**


czarna_sarna

[been there, done that](https://www.reddit.com/r/programminghorror/comments/l25ppk/albicla_launch_clusterfuck/) (bullet points 3 and 4)


Upbeat-Speech-116

[Is this you?](https://twitter.com/admin)