Forum: Ruby on Rails Titles in URL ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A71728118f219c95758cea1af0c4845c?d=identicon&s=25 weirdmonkey (Guest)
on 2006-03-31 17:29
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!
6578456ff00ab3520b1fe684bc572b45?d=identicon&s=25 Łukasz Piestrzeniewicz (Guest)
on 2006-03-31 19:08
(Received via mailing list)
Try this snippet:

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

Regards,
Łukasz
0f23274e975611727e4ad46d745d298e?d=identicon&s=25 bill (Guest)
on 2006-03-31 22:34
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
D5145c421cd25af6fa577c15219add90?d=identicon&s=25 unknown (Guest)
on 2006-03-31 23:41
(Received via mailing list)
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
A71728118f219c95758cea1af0c4845c?d=identicon&s=25 weirdmonkey (Guest)
on 2006-04-01 19:06
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
7b8adabc68bcdcf2df5ea4a8441cecc4?d=identicon&s=25 Colin (Guest)
on 2006-04-01 20:01
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
This topic is locked and can not be replied to.