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! -- Posted via http://www.ruby-forum.com/.
Try this snippet: http://www.bigbold.com/snippets/posts/show/1818 Regards, ?ukasz On 31/03/06, weirdmonkey <xfile7@hotmail.com> wrote:> 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! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- ?ukasz Piestrzeniewicz http://ragnarson.blogspot.com
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-- Posted via http://www.ruby-forum.com/.
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 On 31/03/06, bill <devaulw@onebox.com> wrote:> 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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"? > -Nit is a French website, so I only want to replace non-standar caracter from URL and keep all accents, etc, in the article -- Posted via http://www.ruby-forum.com/.
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 articleIt 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 -- Posted via http://www.ruby-forum.com/.