On Feb 22, 2010, at 4:39 PM, GoodGets wrote:

I guess my thinking was that I only wanted to catch potential
errors.

Yes your way definitely works and it's probably a bit easier on rails,
so thank you.

But wouldn't that method also limit all usernames to their downcased
versions?  Like a user could never have an example.com/FirstnameLast
url could they?

Yep, but you can't have it both ways. If you have users JoeBob and JOEbob and the browser requests "JoEbOb", which record do you return? You have to pick one and half the time you'll pick wrong.

What you could do is require uniqueness on username's regardless of caps, but let them use caps to make username's easier to read... then you wouldn't have the conflict.

If it were me, I'd force them all lower case and be done with it :)


Also, scribed is accomplishing this correctly.  It displays any
variation of upcased/downcased letters in the url address, but still
displays the user's profile correctly.  Is this a rails feature, or
hack, or some kind of Apache or database feature?

No idea.


Phillip thank you again for your input.

On Feb 22, 7:13 pm, Philip Hallstrom <[email protected]> wrote:
On Feb 22, 2010, at 4:10 PM, GoodGets wrote:





I've mapped my users' usernames off my root path to give them vanity
urls, (i.e. example.com/username), but if you capitalize any of the
letters of their username, rails throws an exception.  It's looking
for the case sensitive version of that name.  So for instance,
example.com/username works, but example.com/USErNamE doesn't.

I fixed the problem by putting this in my applications_controller.rb:

 rescue_from NoMethodError do |exception|
    if request.url != request.url.downcase
       redirect_to request.url.downcase
    else
       flash[:error] = "That doesn't seem to exist."
       redirect_to root_path
    end
 end

All it does is downcases the url, then tries that new url. I actually found that solution on an answer to a stack overflow question that was asking about case insensitive urls. Side note, stackoverflow doesn't
seem to be case sensitive, like stackoverflow.com/QueStioNS still
displays the proper page and does no downcasing.  However, I don't
think they are built on rails, but twitter accomplishes this, too.
Like, twitter.com/eV still routes to the correct page with no
downcasing hack.  It actually displays the upcased url but still
routes to the correct path.  How are they doing this?

Or, how are you solving this?

In the action that handles user's username's requests, why wouldn't
you simply downcase the parameter you are passing to your User model's
find method?

Ie...

map.user ':user', :controller => 'foo', :action => 'bar'

# in your Foo controller...

def bar
   User.find_by_username(params[:user].downcase)
   #....
end

Wouldn't that work?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails- [email protected]. To unsubscribe from this group, send email to [email protected] . For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en .


--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to