title: How to define constraint for encoded parameter segment properly in rails?
body: <p>Say we have a path for user in our site, which is defined like this in <code>routes.rb</code></p>
  
  <pre><code>get '/users/:username' =&gt; 'users#show', as: 'u', constraints: {username: /[A-Za-z0-9\_]+/}
  </code></pre>
  
  <p>it works well, and invalid username will just pass, then one day, we decide to allow people to use Chinese characters as a part of their usernames, the format will be extended to <code>/[\u4e00-\u9fa5A-Za-z0-9_]/</code>. So comes to the problem, because Chinese characters will be encoded to <code>%FF</code> format string, we can't use that constraint, how to define the constraint properly to make the rule work just like before?</p>
  
  <p>I have tried to step back, just to make the route work, use <code>/[%A-Za-z0-9\_]+/</code> format, the income request will at least work, but when I call <code>u_path</code>, this constraint will just fail.</p>
  
  <p>The problem is when to match request, Rails will use the origin incoming format, and when construct path, it will use the decoded format.</p>
  
  <p>How to handle this situation?</p>
  
  <p>I am using Rails 3.2.12.</p>