WIth ruby 1.8.7 and rails 3.0.3 on Mac OS I always got "&#...;" characters in ERB template output running rspec 2.4 controllers tests (with integrate_views).
Besides "&" character and Cyrillic characters are always escaped, even using <%= raw '...' or html_safe methods.
Can anybody give a clue - what's going on here?
You mean console/terminal output?
Try editing you ~/.profile file and pasting this line:
export LANG=sr_YU.UTF-8
You can find listing of all available locales here.
Replace sr_YU with your own cyrillic locale.
Related
I allready have problems with utf-8 encoding in my ror app ...
some are fixed now. But some are still left.
I have now an utf-8 force in my layout
But still have problems with German special chars (ä, ö, ü). In my /config/locales/de.yml I have lots of them. In the File they look nice :) tested with rubymine and nano.
But when I start the app it crashes. The yml is encoded in utf-8 ..
I've also tried this:
f\xC3\xBCr --> should be für
always got this:
incompatible character encodings: UTF-8 and ASCII-8BIT
Does anyone have some hints for me?
It seems to me that the encoding of the app is set to UTF-8.
Are you sure that RubyMine saves your file with UTF-8?
You can add
# encoding: UTF-8 to the top of your files to assure it is set. (Not sure if this works in .yml)
Edit:
If you have pasted any text into the file it may still contain wrong encoding.
Move the de.yml out of the project.
Create a new file de.yml
de:
first_translation: Ich möchten ein bisschen Müsli
If this works, then you need to rewrite everything from the old file, no copying!
I'm using the DocSplit gem for Ruby 1.9.3 to create Unicode UTF-8 versions of word documents. To my surprise today while I was running a test on a particular piece of one of these documents I started running into character encoding inconstencies.
I have tried a number of different methods to resolve the issue which I will list below, but the best success I've had so far is to remove all non-ASCII characters. This is far from ideal, as I don't think the character's are really going to be all that problematic in the DB.
gsub(/[^[:ascii:]]/, "")
This is a sample of what my output looks like vs. what I'm expecting:
My CODES'S APOSTROPHE
My CODES’S APOSTROPHE
The second apostrophe should look squiggly. If you paste it into irb, you get the following: \U+FFE2
I tried Regexing specifically for this character and it appears to work in Rubular. As soon as I put it in my model however, I got a syntax error.
syntax error, unexpected $end, expecting ')'
raw_title = raw_title.gsub(/’/, "")
I also tried forcing the encoding to UTF-8, but everything is already in UTF-8 and this does not appear to have an effect. I tried forcing the output to US-ASCII, but I get a byte sequence error.
I also tried a few of the encoding options found in Ruby library. These basically did the same thing as the Regex.
This all comes down to that I'm trying to match output for testing purposes. Should I even be concerned about these special characters? Is there a better way to match these characters without blindly removing them?
Try adding:
# encoding: utf-8
at the top of the failing rspec file. This should ensure things like:
raw_title = raw_title.gsub(/’/, "")
in your spec work.
I tried using the above example. but even after that it kept failing. So I used iconv to convert that specfic character. THis is what I used
Iconv.conv('ASCII//IGNORE', 'UTF8', text_to_be_converted)
I tried what was given in the following link - How to get rid of non-ascii characters in ruby
Update-edit: Here is the requested information.
Used both Rubymine 3.2.4 and the EAP version (113.2).
JRuby: 1.6.6-p357
Windows 7 64 bit
I've double checked the UTF8 config, in the IDE: File -> Settings -> General, and in the file located in ....RubyMine40\config\options\encoding.xml, both are set to UTF-8.
I have tried to set #encoding: utf-8 in my .feature file, but it still shows my special chars (æøå) as ?. Actually, it won't even run the test if I use these characters in the code under
Feature: This is some test # Feature = Egenskap in norwegian
I opened the .feature file that I created in RubyMine 4.0 (EAP) in Notepad++, and it says its coded in ANSI as UTF-8.
The question
I have a problem with special characters, in my case, æ ø å. I use RubymMine to develop cucumber tests. My IDE encoding is set to use UTF-8.
The problem is, that when I run the tests in my RubyMine, the console simply replace my special chars (æøå) with ?, which is annoying, and this also happens when I do a HTML export of the tests. I can write the .feature files in my langauge no problem,using #language: no comment at the top of feature file. It only gets messy when Rubymine outputs to console, and export the results.
Has anyone had a similar problem and knows how to solve it? Or can just point me in the right direction?
<a class="close" href="#">×</a>
I get an error regarding the use of ×.
It's used in error messages on twitter's bootstrap framework, I get an invalid byte sequence in UTF-8 error when I try to use it. Is there any work-around? Apart from using a normal x or X.
I have:
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
In my application.rb
This seems almost too simple, but why aren't you using ×?
You need to set the encoding at the top of the file where that character is used. You can do this with:
# coding: utf-8
class MyClass
end
I haven't tried it in an erb file, but I don't see why that would be any different. I think you can use the word "encoding" too instead of just "coding" if that feels better. All that is required is at minimum "coding".
What editor are you using?
I suspect that you are saving the source file using an encoding other than UTF-8 (such as Latin-1 or ANSI on Windows), which is then causing ruby to fail to interpret the file correctly.
I've tried adding the times symbol to one of my views (using HAML) and it worked correctly. I'm using VIM as my editor and saving in UTF-8 without any BOM.
#encoding: utf-8
class ClassiClass
end
everything works fine!
I am using rails 2.3.3 and ruby 1.9.1.
I am trying to render a view that includes a partial. In the partial i output a field of a model that is encoded in UTF8.
This fails with
ActionView::TemplateError (incompatible character encodings: ASCII-8BIT and UTF-8) on line #248 of app/views/movie/show.html.erb:
245: <!-- Coloumn right | start -->
246: <div class="col_right">
247:
248: <%= render :partial => 'movie_stats' %>
249:
250: <!-- uploaders -->
251: <div class="box_white">
On the other hand, i can output the field with utf8 content just fine if i directly use that field in a view (when it is not in a partial).
How can i fix this?
I already tried setting the default encoding but that did not seem to work.
I just had this as well so I think its worth having the correct answer.
The 2.8.1 MySql gem is not utf-8 friendly, so it sometimes will return UTF strings and lie to Rails, telling it that they are ASCII when in fact they are UTF-8. This makes things explode.
So: you can either monkey patch or get a compatible MySql gem. See: http://gnuu.org/2009/11/06/ruby19-rails-mysql-utf8/
There appears to be an issue with ERB's encoding in Ruby 1.9. More details are in this Lighthouse ticket. A patch with a workaround has been included, perhaps it works for you?
The problem is erb code in ruby 1.9 distribution. When it compiles the template code it forces a 'ASCII-8bit' encoding, the problem is when the template code has multibyte characters the template code is returned in a 'ASCII-8bit' string and when this string is concat with a 'UTF8' string with multibyte character the exception is raised because the strings between this encodings are only compatible when both only have seven-bit characters.
There seems to be an incompatibility between Ruby 1.9x and the mysql gem with regard to how strings are passed back and forth (specifically the encoding of the strings).
To fix, run
gem install mysql2
on the server and update the database configuration file to use this gem instead of the previous one.