Titles in URL?


#1

Hi!

I have an article website and would like to have the title of the
article in the URL. and not domain.com/show/id

ie: http://domain.ck/articles/how-to-become-a-ror-master/

How to change a title with special caracters like: ', :, é, !. to
something that works in the URL.

Thank you!


#2

Try this snippet:

http://www.bigbold.com/snippets/posts/show/1818

Regards,
Łukasz


#3

Rather than try to remove all odd characters, why not permit only valid
characters like [a-zA-Z0-9_-]? I use this (outside of RoR) to limit
injections as well.

Bill

Łukasz Piestrzeniewicz wrote:

Try this snippet:

http://www.bigbold.com/snippets/posts/show/1818

Regards,
Łukasz


#4

But that would just mean any other characters are simply missed out,
which isn’t quite as user-friendly as if they were replaced with
keyboard-friendly characters. If you were using a site like that, and
you wanted to get to the article “When (not) to add jalepeños to your
cooking”, would you rather type “jalepenos” or “jalepeos”?
-N


#5

weirdmonkey wrote:

unknown wrote:

But that would just mean any other characters are simply missed out,
which isn’t quite as user-friendly as if they were replaced with
keyboard-friendly characters. If you were using a site like that, and
you wanted to get to the article “When (not) to add jalepeños to your
cooking”, would you rather type “jalepenos” or “jalepeos”?
-N

it is a French website, so I only want to replace non-standar caracter
from URL and keep all accents, etc, in the article

It could probablky be done in a nicer way but:

def Format.slug text
require ‘iconv’
begin
tempText = Iconv.conv(“ASCII//TRANSLIT”, “ISO-8859-15”, text)
rescue Exception
tempText = text
end
tempText.downcase.strip.gsub(/\s+/ , ‘’).gsub(/[^a-z0-9]/,
‘’).gsub(/+/ , '’)
end


#6

unknown wrote:

But that would just mean any other characters are simply missed out,
which isn’t quite as user-friendly as if they were replaced with
keyboard-friendly characters. If you were using a site like that, and
you wanted to get to the article “When (not) to add jalepeños to your
cooking”, would you rather type “jalepenos” or “jalepeos”?
-N

it is a French website, so I only want to replace non-standar caracter
from URL and keep all accents, etc, in the article