0
votes

I have a very common trouble in ruby 1.9.2 and rails 3.0.9 – incompatible character encodings: UTF-8 and ASCII-8BIT exception. It is raised when i use thinking_sphinx search.

def result
  #return page(1).per(1) #no any exceptions
  return search('').page(1).per(1) #if I use this an exception is raised when i try to render partial
end

Then the result of this method is used in the partial

render Trademarks.result

I use both erb and haml (makeup man use html, and I prefer to use haml), but it's allowed by haml referrence.

I've tried magic comments, default_internal, external and some other advices, but with no results. Any ideas?

2
Exception is raised only when I use trademark.excerpts.something. It seems, here is the cause of the problem. Maybe excerpts add incompatible symbols when highlights found words? I've created an issue here github.com/freelancing-god/thinking-sphinx/issues/262Alexander Ulitin

2 Answers

3
votes

Ok, the solution is to use model_name.excerpts.something with force_encoding('utf-8'), because it doesn't return UTF string.

0
votes

Does the exception get raised if you return the results via a standard activerecord query?

If your database has invalid utf-8 in it then the encoding of your model string attributes could be conflicting with your view encoding.