0

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?

Alexander Ulitin
  • 1,150
  • 1
  • 10
  • 23
  • 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 https://github.com/freelancing-god/thinking-sphinx/issues/262 – Alexander Ulitin Aug 01 '11 at 09:43

2 Answers2

3

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

Alexander Ulitin
  • 1,150
  • 1
  • 10
  • 23
  • 1
    Also it's fixed in `gem 'riddle', :git => 'git://github.com/freelancing-god/riddle.git'` and will be fixed in next release of TS. – Alexander Ulitin Aug 02 '11 at 08:57
0

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.

James Healy
  • 14,557
  • 4
  • 33
  • 43
  • As I've already told I have no any problems with AR queries. Trademark.page(1).per(1).to_sql is "SELECT `trademarks`.* FROM `trademarks` LIMIT 1 OFFSET 0". DB is in utf-unicode-ci – Alexander Ulitin Aug 01 '11 at 09:00