On Jun 3, 4:37 am, Japmsn Japms <li...@ruby-forum.com> wrote: > okay lol forget about the "nil" problem I mentioned at the end, that was > because out of the huge list of words there were a few that started with > a symbol other than a kanji so just doing: > > "k.id unless k.nil?" did the trick > > so I'm going to change my question to... is there another(simpler) way > to do this? right now my helper looks like crap, I mean... like this: > > ************************************* > def word_to_links(word) > parts, o = [], "" > (word.size/3).times{ |i| parts << word[i*3,3] }
I wouldn't rely on some or most kanjis being exactly 3 bytes in utf8 - use the multibyte chars stuff in activesupport Fred > parts.each do |part| > k = Kanji.find(:first, :conditions => "kanjis.kanji = '#{part}'") > o << (k.nil? ? part : link_to(part, "/kanjis/#{k.id}")) > end > o > end > ************************************* > > Thanks. > -- > Posted viahttp://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.