Rob
Rob

Reputation: 1855

Can friendly-id gem work with capital letters in url e.g. /users/joe-blogs and /users/Joe-Blogs both work

I like the friendly id gem but one problem i'm seeing is when I type in a url with a capitol letter in it such as /users/Joe-Blogs it cant find the page. Its a little trivial but most sites can handle something like this and will generate the page whether it has a capitol letter or not. Does anyone know a fix for this?

Edit: to clarify this is for when users enter a url manually and put capitals in it just because its a name like author/Joe-Blogs. I've seen other sites handle this but rails seems to just give a 404.

Upvotes: 1

Views: 267

Answers (2)

Richard Peck
Richard Peck

Reputation: 76784

As an addition to Vic's answer, you'll want to look at url normalization:

The following normalizations are described in RFC 3986 to result in equivalent URLs:

Converting the scheme and host to lower case.

The scheme and host components of the URL are case-insensitive. Most normalizers will convert them to lowercase.

Example: HTTP://www.Example.com/ → http://www.example.com/

In short - it's against convention to use capitalization in your urls.

You may also wish to look at URI normalize; more importantly, you should work to remove the capitalization from your URLs:

URI.parse(params[:id]).normalize

Upvotes: 1

Vic
Vic

Reputation: 1542

friendly_id uses parameterize to create the slugs.

I think the best way to solve your problem is to parameterize the params before using it to find.

# controller
User.find(params[:id].parameterize)

Or parameterize the url where the link originated from.

Upvotes: 4

Related Questions