Forum: Ruby on Rails Ajax call and latin1?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5b2bde5812466012d9dde870c258254f?d=identicon&s=25 fabienpenso (Guest)
on 2005-11-16 11:02
(Received via mailing list)
Hi.

I use a form_remote_tag and use latin1 in mysql and rails. But the
ajax call send utf8 and not latin1.
Anyone knows a way to change that ?

Thanks.

--
http://penso.info/
5b2bde5812466012d9dde870c258254f?d=identicon&s=25 fabienpenso (Guest)
on 2005-11-16 11:11
(Received via mailing list)
> I use a form_remote_tag and use latin1 in mysql and rails. But the
> ajax call send utf8 and not latin1.
> Anyone knows a way to change that ?

Ok I feel bad, it's out there already:
http://dema.ruby.com.br/articles/2005/07/22/playin...

For list archive :

require 'iconv'
class ApplicationController < ActionController::Base
  before_filter :convert_xhr

  ICONV = Iconv.new('ISO-8859-1', 'UTF-8')

  def convert_xhr
    convert_hash(params) if request.xhr?
  end

  def convert_hash(hash)
    for k, v in hash
      case v
      when String: hash[k] = ICONV.iconv(v)
      when Array: hash[k] = v.collect { |v| ICONV.iconv(v) }
      when Hash: convert_hash(v)
      end
    end
  end
This topic is locked and can not be replied to.