Hi guys, my problem is the following,

Right now I have a list of japanese words that are loaded from the
database, they display okay, the problem begins when I need to split
that word into 'characters' in this case 'kanjis' so I can make a link
for each kanji,for example:

****************************
I have on my view:
<%= word.kanji %> which display 何曜日

But what I need is something like:
<a href='/kanjis/12'>何</a><a href='/kanjis/55'>曜</a><a
href='/kanjis/39'>日</a>
****************************

So I decided to go one step at a time, first split the thing... but
using each_char didn't work because it seems that the string '何曜日' is
being manipulated as '\xE4\xBD\x95\xE6\x9B\x9C\xE6\x97\xA5' which is
ASCII-8BIT.

Then I tried going 3 bytes a time which allowed me to split it by kanji,
it was something like this

****************************
parts = []
(word.size/3).times{ |i| parts << word[i*3,3] }
****************************

Now "parts" has each kanji stored and when I try to make a query with
it, something like:
k = Kanji.find(:first, :conditions => "kanji = '#{parts[0]}'")
everything seems ok, I even get:
k.class => Kanji
k.methods => (lots including :id)
k.nil? => false

but when I try:
k.id
I get:
undefined method `id' for nil:NilClass

So I'm really confused, I'm pretty noob at both ruby and rails so Idk if
I'm doing something really stupid or the wrong way, I've tried doing
encode, toutf8 and stuff like that but it still gets me nowhere, I'm
worried because with this I may not be able to do a search feature by
kanji.

Thanks in advance.
-- 
Posted via http://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.

Reply via email to