4 ms·
For RoR, you can override to_param on the model in question, something like: class User < ActiveRecord::Base def to_param self.login end ..
by gaelian 16y ago
For RoR, you can override to_param on the model in question, something like:
class User < ActiveRecord::Base
def to_param
self.login
end
...
end
Assuming self.login is reliably unique. Although I've found this can still have some follow on effects that could need to be handled in a situation similar to the above. There are also some heavier weight, more feature filled options of course.
- yummyfajitas 16y agoSome of the heavyweight ones are nice as far as human readability goes. Consider the AutoSlugField (in Django). Say you have an object, Item(name='Phillip Lim Pleated printed silk-chiffon dress', description='...). Which link is less scary? http://secret-project/item/phillip-lim-pleated-printed-silk-chiffon-dress http://secret-project/item/phillip-lim-pleated-printed-silk-... or http://secret-project/item/47a61d7c-dde1-11df-ba19-0026c72a6914 http://secret-project/item/47a61d7c-dde1-11df-ba19-0026c72a6...
- lincolnq 16y agoFunny! I've come to associate slug-type URLs (like the former, that have no numbers or anything in the URL) with content-free websites that have been SEO'd. The latter is also scary though, because it's too MANY random-ass numbers. I have sort've come to expect a combination of a numeric identifier and readable words for reputable sites.
- isb 16y agoThe second link although ugly is less "guessable" if you want to skimp on the authorization check. That aside, sometimes an entity might not have a natural key that can be slugified (e.g. an invoice), in which case UUID is better. Also, using a generating/looking-up a UUID might be faster?