我有一個問題,出口與元音變音數據(如「ä」,「ü」...)在CSV文件。我嘗試了不同的解決方案,但沒有任何效果這裏是我的代碼:變音不起作用,通過導出一個CSV文件
控制器:
def bom_export
@configurations = []
@bom = []
params[:configurations].each do |configuration_id|
@configurations << Configuration::Configuration.find(configuration_id.to_i)
end
@configurations.each do |conf|
conf.bill_of_materials.each do |material|
@bom << material
end
end
respond_to do |format|
format.csv {
csv_string = CSV.generate do |csv|
csv << ["Id", "Titel", "Beschreibung", "Breite", "Höhe", "Länge"]
@bom.each do |bom|
csv << [bom.id, bom.title, bom.description, bom.width, bom.height, bom.length]
end
end
c = Iconv.new('ISO-8859-15','UTF-8')
send_data(c.iconv(csv_string),
:type => 'text/csv; charset=iso8859-1; header=present',
:filename => "test.csv")
}
end
end
服務器日誌:
Started GET "/admin/customer_orders/61/configuration_configurations" for 127.0.0.1 at 2014-01-06 16:27:31 +0100
SyntaxError (/Users/shop-it1/workspace/shop/app/controllers/configuration/configurations_controller.rb:106: invalid multibyte char (US-ASCII)
/Users/shop-it1/workspace/shop/app/controllers/configuration/configurations_controller.rb:106: invalid multibyte char (US-ASCII)
/Users/shop-it1/workspace/shop/app/controllers/configuration/configurations_controller.rb:106: syntax error, unexpected $end, expecting ']'
… "Beschreibung", "Breite", "Höhe", "Länge"]
… ^):
Rendered /Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (42.2ms)
Error during failsafe response: ActionView::Template::Error
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.0.10/lib/active_support/core_ext/string/output_safety.rb:23:in `gsub'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.0.10/lib/active_support/core_ext/string/output_safety.rb:23:in `html_escape'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb:7:in `___sers_shop_it___rvm_gems_ruby_______p__gems_actionpack________lib_action_dispatch_middleware_templates_rescues_diagnostics_erb___3189230765086009151_70220166701020_1793258824290671195'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.0.10/lib/action_view/template.rb:135:in `block in render'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.0.10/lib/active_support/notifications.rb:54:in `instrument'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.0.10/lib/action_view/template.rb:127:in `render'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.0.10/lib/action_view/render/rendering.rb:59:in `block in _render_template'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.0.10/lib/active_support/notifications.rb:52:in `block in instrument'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.0.10/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.0.10/lib/active_support/notifications.rb:52:in `instrument'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.0.10/lib/action_view/render/rendering.rb:56:in `_render_template'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.0.10/lib/action_view/render/rendering.rb:26:in `render'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.0.10/lib/action_dispatch/middleware/show_exceptions.rb:88:in `rescue_action_locally'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.0.10/lib/action_dispatch/middleware/show_exceptions.rb:68:in `render_exception'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.0.10/lib/action_dispatch/middleware/show_exceptions.rb:59:in `call'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.0.10/lib/rails/rack/logger.rb:13:in `call'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.2.4/lib/rack/runtime.rb:17:in `call'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/activesupport-3.0.10/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.2.4/lib/rack/lock.rb:11:in `block in call'
<internal:prelude>:10:in `synchronize'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.2.4/lib/rack/lock.rb:11:in `call'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/actionpack-3.0.10/lib/action_dispatch/middleware/static.rb:30:in `call'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.0.10/lib/rails/application.rb:168:in `call'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.0.10/lib/rails/application.rb:77:in `method_missing'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.0.10/lib/rails/rack/log_tailer.rb:14:in `call'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.2.4/lib/rack/content_length.rb:13:in `call'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.2.4/lib/rack/chunked.rb:15:in `call'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/thin-1.3.1/lib/thin/connection.rb:80:in `block in pre_process'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/thin-1.3.1/lib/thin/connection.rb:78:in `catch'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/thin-1.3.1/lib/thin/connection.rb:78:in `pre_process'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/thin-1.3.1/lib/thin/connection.rb:53:in `process'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/thin-1.3.1/lib/thin/connection.rb:38:in `receive_data'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/thin-1.3.1/lib/thin/backends/base.rb:61:in `start'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/thin-1.3.1/lib/thin/server.rb:159:in `start'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.2.4/lib/rack/handler/thin.rb:14:in `run'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.2.4/lib/rack/server.rb:217:in `start'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.0.10/lib/rails/commands/server.rb:65:in `start'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.0.10/lib/rails/commands.rb:30:in `block in <top (required)>'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.0.10/lib/rails/commands.rb:27:in `tap'
/Users/shop-it1/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.0.10/lib/rails/commands.rb:27:in `<top (required)>'
/Users/shop-it1/workspace/shop/script/rails:6:in `require'
/Users/shop-it1/workspace/shop/script/rails:6:in `<top (required)>'
-e:1:in `load'
-e:1:in `<main>'
試圖保存的CSV文件服務器崩潰(500)之後。沒有變音器一切正常。
也許那裏是另一種沒有Iconv的解決方案,因爲Iconv已被棄用(?) – levitas111
請發佈您在'log/development.log'中獲得的錯誤消息。 – phoet
UTF-8應該與德文字符集一起工作得很好。爲什麼你甚至會轉換它? – phoet