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? 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? 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 [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.

