Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9187537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:47:38+00:00 2026-06-17T19:47:38+00:00

I have a text file that has some ® (Registered Trade Mark) symbols in

  • 0

I have a text file that has some ® (Registered Trade Mark) symbols in it. The file is in UTF-8.

I’m trying to import this file and populate a MySQL database using Rails 3. The DB appears to be setup fine to take UTF-8

+-------------+--------------+-----------------+------+-----+---------+----------------+---------------------------------+---------+
| Field       | Type         | Collation       | Null | Key | Default | Extra          | Privileges                      | Comment |
+-------------+--------------+-----------------+------+-----+---------+----------------+---------------------------------+---------+
| id          | int(11)      | NULL            | NO   | PRI | NULL    | auto_increment | select,insert,update,references |         |
| user_id     | int(11)      | NULL            | YES  | MUL | NULL    |                | select,insert,update,references |         |
| title       | varchar(255) | utf8_general_ci | YES  |     | NULL    |                | select,insert,update,references |         |
| translation | text         | utf8_general_ci | YES  |     | NULL    |                | select,insert,update,references |         |
| created_at  | datetime     | NULL            | NO   |     | NULL    |                | select,insert,update,references |         |
| updated_at  | datetime     | NULL            | NO   |     | NULL    |                | select,insert,update,references |         |
+-------------+--------------+-----------------+------+-----+---------+----------------+---------------------------------+---------+

Yet, when I try to do this:

trans_file = params[:descriptions] #coming from file_field_tag
trans = trans_file.read.split("\r\n")
trans.each do |tran|
  ttl = ''
  desc = ''
  tran.split(']=').each do |title|
    if title =~ /\[/ #it's the title
      ttl = title.sub('[','')
    else
      desc = title.gsub('FFF', "\r\n")
    end
  end
  @current_user.cd_translations.build(title: ttl, translation: desc).save

I’m getting the error “Action Controller: incompatible character encodings: ASCII-8BIT and UTF-8”.

I’m using the utf-8 encoding in my application.rb file, and I’m using the mysql2 gem.

If I remove the Registered Trade Mark character, the error goes away. But it’s not really an option to strip it out of the incoming text.

I tried the solution here: https://stackoverflow.com/a/5215676/102372, but that didn’t make any difference.

Stack trace:

app/controllers/users_controller.rb:28:in `block in update_cd_translations'
app/controllers/users_controller.rb:15:in `each'
app/controllers/users_controller.rb:15:in `update_cd_translations'
config/initializers/quiet_assets.rb:7:in `call_with_quiet_assets'

How can I resolve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:47:39+00:00Added an answer on June 17, 2026 at 7:47 pm

    It appears that ruby thinks that the encoding of the uploaded file is ascii-8bit (that is to say binary).

    If you know the encoding of the file, you can use force_encoding! to change the encoding of the string (without transcoding). If you’re not always going to be sure of the encoding of the file, the charguess gem can be used to guess it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that has some invalid byte sequences. Emacs renders these
I have a C++ Windows program. I have a text file that has some
I have a C# file that has some arabic text in it, I got
I have some json that is in a text file that has already been
I have a simple WPF (XAML) file that has some animated shapes and text.
I have a text file that has item numbers in it (one per line).
I currently have a text file that has the following: 1 Commercial & Enterprise
I have a text file that I want to edit using Java. It has
i have a java ee project which has a text file that uses a
So I have a multipart form that has fields for text, integers and file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.