Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't confuse file encoding with string encoding</p> <p>The purpose of the <strong><code>#encoding</code> statement at the top of files is to let Ruby know during reading / interpreting your code, and your editor know how to handle any non-ASCII characters while editing / reading the file</strong> -- it is only necessary if you have at least one non-ASCII character in the file. e.g. it's necessary in your config/locale files.</p> <p><strong>To define the encoding in all your files at once</strong>, you can <strong>use the <a href="https://github.com/m-ryan/magic_encoding" rel="nofollow noreferrer">magic_encoding</a> gem</strong>, it can insert uft-8 magic comment to all ruby files in your app.</p> <p>The error you're getting at runtime <strong><code>Encoding::CompatibilityError</code> is an error which happens when you try to concatenate two Strings with different encoding during program execution, and their encodings are incompatible.</strong></p> <p>This most likely happens when:</p> <ul> <li><p>you are using L10N strings (e.g. UTF-8), and concatenate them to e.g. ASCII string (in your view)</p></li> <li><p>the user types in a string in a foreign language (e.g. UTF-8), and your view tries to print it out in some view, along with some fixed string which you pre-defined (ASCII). <strong><code>force_encoding</code> will help</strong> there. There's also <strong><code>Encoding::primary_encoding</code> in Rails 1.9 to set the default encoding for new Strings.</strong> And there is <code>config.encoding</code> in Rails in the config/application.rb file.</p></li> <li><p>String which come from your database, and then are combined with other Strings in your view. (their encodings could be either way around, and incompatible). </p></li> </ul> <p>Side-Note: <strong>Make sure to specify a default encoding when you create your database!</strong></p> <pre><code> create database yourproject DEFAULT CHARACTER SET utf8; </code></pre> <p><strong>If you want to use EMOJIs in your strings:</strong></p> <pre><code> create database yourproject DEFAULT CHARACTER SET utf8mb4 collate utf8mb4_bin; </code></pre> <p>and all indexes on string columns which may contain EMOJI need to be 191 characters in length. CHARACTER SET utf8mb4 COLLATE utf8mb4_bin</p> <p>The reason for this is that normal UTF8 uses up to 3 bytes, whereas EMOJI use 4 bytes storage.</p> <p><strong>Please check this Yehuda Katz article</strong>, which covers this in-depth, and explains it very well: (there is specifically a section 'Incompatible Encodings')</p> <p><a href="http://yehudakatz.com/2010/05/05/ruby-1-9-encodings-a-primer-and-the-solution-for-rails/" rel="nofollow noreferrer">http://yehudakatz.com/2010/05/05/ruby-1-9-encodings-a-primer-and-the-solution-for-rails/</a></p> <p><a href="http://yehudakatz.com/2010/05/17/encodings-unabridged/" rel="nofollow noreferrer">http://yehudakatz.com/2010/05/17/encodings-unabridged/</a></p> <p>and:</p> <p><a href="http://zargony.com/2009/07/24/ruby-1-9-and-file-encodings" rel="nofollow noreferrer">http://zargony.com/2009/07/24/ruby-1-9-and-file-encodings</a></p> <p><a href="http://graysoftinc.com/character-encodings" rel="nofollow noreferrer">http://graysoftinc.com/character-encodings</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload