Note that there are some explanatory texts on larger screens.

plurals
  1. POThings to change when using username slug/short URL in rails
    primarykey
    data
    text
    <p>I'm pretty new at rails, so forgive me if I'm overlooking simple things or the rails way. My objective is to completely replace URLs of the form </p> <p><code>/users/1</code></p> <p>with</p> <p><code>/username</code></p> <p>for all purposes. (I think exposing IDs scaffolding publicly is like walking around with a bone sticking out of your arm.) But implementing seems a little more complicated than I expected. This seems to change the entire way rails indexes and looks up users, rather than just substituting a lookup method.</p> <p>Although I've kind of gotten this to function using the <code>to_param</code> override in my <code>user.rb</code> file, I've read this means I'll have <a href="http://apidock.com/rails/ActiveRecord/Base/to_param" rel="nofollow noreferrer">indexing</a> <a href="http://blog.nhocki.com/2012/01/22/beautiful-urls-in-rails-the-easy-way" rel="nofollow noreferrer">problems</a> <a href="https://stackoverflow.com/questions/5611649/ruby-on-rails-routing-matching-username">down</a> the road when using <code>params([:username])</code>, and I'm not sure how it will impact my </p> <p>(a) session model at new user creation, and </p> <p>(b) @User usage in the user/show.html.erb file.</p> <p>So, I've either consulted the following pages (or asked the questions):</p> <ul> <li><a href="https://stackoverflow.com/questions/5611649/ruby-on-rails-routing-matching-username">Ruby on rails routing matching username</a></li> <li><a href="https://stackoverflow.com/questions/2269885/username-in-url-with-rails-routes">customize rails url with username</a></li> <li><a href="https://stackoverflow.com/questions/11048063/routing-in-rails-making-the-username-an-url">Routing in Rails making the Username an URL:</a></li> <li><a href="https://stackoverflow.com/questions/5204057/routing-error-with-username-in-url">routing error with :username in url</a></li> <li><a href="https://stackoverflow.com/questions/11514723/correct-routing-for-short-url-by-username-in-rails/11514977#comment15244810_11514977">Correct routing for short url by username in Rails</a></li> <li><a href="https://stackoverflow.com/questions/6461814/rails3-clean-url-friendly-id-sessions">rails3, clean url, friendly_id, sessions</a></li> </ul> <p>The major issues I'd like to understand from this question:</p> <ol> <li>What functionality do I lose by transitioning to this? That is, what things currently "just work" in rails that I'll have to address and rewrite if I pursue this replacement?</li> <li>As a practice, is this something better to replace with <a href="http://railscasts.com/episodes/314-pretty-urls-with-friendlyid" rel="nofollow noreferrer">friendly_id</a>? My concern here is that creating a slug column in my DB identical to the username seems a little non-DRY and makes me uncomfortable, and I'd rather avoid dependencies on external gems where possible.</li> <li>What does my users#show need to look like?</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload