我遇到涉及rails会话存储和UTF8的问题。似乎当我将一些来自Omniauth的变量保存到我的会话中时,我之后得到了ASCII-8BIT。
我在我的applications.rb文件中设置了UTF8,UFT8在其他任何地方都能正常工作。
config.encoding = "utf-8"
Wombieapp::Application.config.session_store :cookie_store, :key => '_wombieapp_session'
野外last_name.encoding.name
"UTF-8"
使用Rails 3.0.10。
从会话中返回ASCII-8BIT
omniauth: {"provider"=>"google_apps", "uid"=>"https://www.google.com/accounts/o8/id?
id=AItOawlx217kz5Tkid0sq5_jIzHGQKupMDI6COc",
"user_info"=>{"email"=>"someemail@gmail.com", "first_name"=>"Joe",
"last_name"=>"Mc\xC3\x99isnean", "name"=>"Joe Mc\xC3\x99isnean"}}
应该是(会前原创):
"omniauth"=>
{"user_info"=>
{"name"=>"Joe McÙisnean",
"last_name"=>"McÙisnean",
"first_name"=>"Joe",
"email"=>"someemail@gmail.com"},
"uid"=>
"https://www.google.com/accounts/o8/id?id=AItOawnQmfdfsdfsdfdsfsdhGWmuLTiX2Id40k",
"provider"=>"google_apps"}
#core
gem 'rails', '3.0.10'
gem 'pg', '0.11.0'
gem 'simple_form'
gem 'client_side_validations'
#authorization
#gem 'devise', '1.4.2'
gem 'devise', '1.2'
gem 'omniauth', '0.2.6'
gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git', :branch => 'rails-3.0'
#heroku
gem 'heroku'
gem 'redcarpet'
gem 'resque', '~> 1.17.1', :require => 'resque/server'
gem 'resque-meta', '1.0.3'
gem 'resque-async_deliver'
gem 'resque-heroku-autoscaler', '~> 0.2.3'
还尝试将Encoding添加到environment.rb
Encoding.default_internal = 'UTF-8'
Encoding.default_external = 'UTF-8'
# Initialize the rails application
Wombieapp::Application.initialize!
我也尝试手动将其粘贴在会话中
session[:omniauth] = {"user_info"=> {"name"=>"Joe McÙisnean", "last_name"=>"McÙisnean", "first_name"=>"Joe", "email"=>"someemail@gmail.com"}}
并出现ASCII错误
SyntaxError in Users::OmniauthCallbacksController#google_apps
/Users/holden/Code/wombie/app/controllers/users/omniauth_callbacks_controller.rb:30: invalid multibyte char (US-ASCII)
/Users/holden/Code/wombie/app/controllers/users/omniauth_callbacks_controller.rb:30: invalid multibyte char (US-ASCII)
/Users/holden/Code/wombie/app/controllers/users/omniauth_callbacks_controller.rb:30: syntax error, unexpected $end, expecting '}'
...user_info"=> {"name"=>"Joe McÙisnean", "last_name"=>"McÙis..