Hi Dan,
>> I need to make some nicenames from my post titles, like:
>> - convert spaces to "-"
>> - delete all the !,?,commas,.,;.:,* from the string
Try something like:
delete all the characters: (Add, or modify characters as needed)
link=@article[:title].gsub(/([''*&^%$+_))((**&&^%$\#@\!~`{}\/\.\,\;])/,
'''' )
create permalink:
[root@srv31 ror]# ruby script/console
Loading development environment.
str=>> str="My long string"
=> "My long string"
>> def create_permalink(string)
>> string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
?> ''%'' + $1.unpack(''H2'' *
$1.size).join(''%'').upcase
>> end.tr('' '', ''-'').downcase
>>
?> end
=> nil
>> permalink=create_permalink(str)
=> "my-long-string"
>>
Modify to your preferences.
>>Oh, and another thing... How can I make permalink this way:
>> Not .../blog/show/4 but .../category/nicename ?
Try something like this in routes.rb
map.connect ''category/:link'', :controller =>
"blog", :action => ''show''
Hope this helps.
Frank
Dan <ljundberg_83@yahoo.it> wrote:
Want to read my Pro Rails book or Pro Server Management book? Become a beta
reader now. Write me to learn more.
Rails Blog: http://railsruby.blogspot.com
MySQL Blog: http://mysqldatabaseadministration.blogspot.com
Linux / Security Blog: http://frankmash.blogspot.com
Programming One Liners: http://programming-oneliners.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060324/a773f2bd/attachment-0001.html