JRuby Rails calls "invalid US-ASCII byte sequence" on for_fields
I have an application that works fine in Rails 4.1.4 with Ruby 2.1.2. When I switch to Rails 4.1.4 from JRuby 1.7.13, I get an encoding type error in polymorphic relationship addresses. I am using UTF-8 for internationalization.
This is the line she breaks into
<%= f.fields_for :addresses do |a| %>
My browser error
ArgumentError at /contacts/new
invalid byte sequence in US-ASCII
And the terminal says
Completed 500 Internal Server Error in 2139ms
ArgumentError - invalid byte sequence in US-ASCII:
org/jruby/RubyRegexp.java:1642:in `==='
activesupport (4.1.4) lib/active_support/core_ext/object/blank.rb:117:in `blank?'
activesupport (4.1.4) lib/active_support/core_ext/object/blank.rb:24:in `present?'
activesupport (4.1.4) lib/active_support/core_ext/object/blank.rb:44:in `presence'
actionview (4.1.4) lib/action_view/helpers/capture_helper.rb:39:in `capture'
actionview (4.1.4) lib/action_view/helpers/form_helper.rb:1860:in `fields_for_nested_model'
actionview (4.1.4) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionview (4.1.4) lib/action_view/helpers/capture_helper.rb:200:in `with_output_buffer'
actionview (4.1.4) lib/action_view/helpers/capture_helper.rb:38:in `capture'
actionview (4.1.4) lib/action_view/helpers/form_helper.rb:699:in `fields_for'
actionview (4.1.4) lib/action_view/helpers/form_helper.rb:1859:in `fields_for_nested_model'
actionview (4.1.4) lib/action_view/helpers/form_helper.rb:1845:in `fields_for_with_nested_attributes'
org/jruby/RubyArray.java:1613:in `each'
activerecord (4.1.4) lib/active_record/relation/delegation.rb:46:in `each'
actionview (4.1.4) lib/action_view/helpers/form_helper.rb:1843:in `fields_for_with_nested_attributes'
actionview (4.1.4) lib/action_view/helpers/form_helper.rb:1517:in `fields_for'
The fragment that I see in lib/active_support/core_ext/object/blank.rb:117
,
#
# "\u00a0".blank? # => true
#
# @return [true, false]
def blank?
BLANK_RE === self
end
I have declared UTF8 in many different places and config files and they check correctly. It doesn't seem to be related to environment variables, but rather embedded code.
I have checked the form representing the utf8 parameter
Parameters: {"utf8"=>"β",
UTF8 configs
config / database.yml
default: &defaults
adapter: postgresql
encoding: utf8
database: mydb
pool: 5
timeout: 5000
development:
<<: *defaults
adapter: postgresql
database: dev_mydb
config / application.rb
config.encoding = "utf-8"
config / boot.rb
ENV_JAVA['file.encoding'] = "UTF-8"
ENV['LC_ALL'] = "en_US.UTF-8"
ENV['LANG'] = "en_US.UTF-8"
ENV['LANGUAGE'] = "en_US.UTF-8"
Gemfile
if RUBY_VERSION =~ /1.9/ # assuming you're running Ruby ~1.9
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
As I said, the code works in Rails 4.1.4 with Ruby 2.1.2. Help is appreciated.
Here is a snippet from my db/schema.rb
address table file
# encoding: UTF-8
create_table "addresses", force: true do |t|
t.integer "kind"
t.string "address1"
t.string "address2"
t.string "address3"
t.string "city"
t.string "state"
t.string "postal_code"
t.string "country"
t.integer "addressable_id"
t.string "addressable_type"
t.datetime "created_at"
t.datetime "updated_at"
end
There is a similar issue mentioned in JRuby articles on github https://github.com/jruby/jruby/issues/1562
source to share
No one has answered this question yet
Check out similar questions: