开发者

incompatible character encodings: UTF-8 and ASCII-8BIT and thinking_sphinx

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 Trade开发者_如何学运维marks.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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜