A basic task: evaluate field's value and show warning if results are not satisfying. The actual code doesn't matter, since it works perfectly until I actually change sample warning's test to the one, which should actually be there, which throws this accursed error at me:
Error: Encoding::UndefinedConversionError: U+0417 from UTF-8 to ISO-8859-1
In any other case I would've used i18n or magic comment, but neither seem to work here, since apparently you can't mix ruby into .coffee file. Is there any way to avoid this without resorting to putting unnecessary javascript into views?
You can use ruby in coffeescript assets. Just rename the file to .js.erb.coffee and use good old <%= ruby_code %>.
Related
By using Kristin Gem, Is there any possible way to store the result of the conversion on a variable instead of outputting it as a file?
Assuming that the link below goes to the gem you are talking about, no. The gem is a very thin layer on top of pdf2htmlEX and simply spawns the process with the arguments passed. Further, pdf2htmlEX doesn't seem to support redirecting its output and adding this feature doesn't seem to be on their todo list, so adding this functionality would require wrapping a different converter.
I think your best bet would be to save load the HTML to a variable after creation.
Kristin:https://github.com/ricn/kristin
Thread about adding output redirection to pdf2htmlEX: https://github.com/coolwanglu/pdf2htmlEX/issues/638
Let's say I have a file called foobar.js.erb.coffee.
I'm confused how this file is interpreted when rails application is compiled. My understanding is like following:
1) Coffeescript preprocessor engine interprets from coffeescript to ruby(erb).
2) ERB preprocessor engine converts ruby to javscript.
Am I understanding this correctly?
For example, foobar.js.erb.coffee
The extension of the file will be composed of two parts: the format (foobar.js) followed by the handler (.erb.coffee).
A handler is a preprocessor for the template, or a templating language. There are a number of handlers built in, and many more can be added by using extra gems.
The order of conversion is from right to left.
In your case, the CoffeeScript engine try to convert CoffeeScript into JavaScript (Error may occur because of existing ERB may cause CoffeeScript has invalid syntax) and then the ERB handlers will replace all the Ruby code to what the output value should be.
I always put .erb at last for these kind of situation. For example, main.css.scss.erb or app.js.es6.erb.
I have installed the less-rails gem as I am keen to use the colour manipulation LESS offers. I need to extract a colour from my database as my themes base colour, and build up from there.
I have the static CSS, and have renamed it styles.css.less to ensure that rails understands the less extension, which it appears to.
The next thing I tried was to also wrap the file as an erb, to hopefully allow ruby string literals to process before being sent to LESS, and eventually outputting as valid CSS (still with me?)
The file is now called style.css.less.erb. While the file simple contains valid CSS, the processing of the document works. As soon as I add a ruby string literal, it fails.
color: #{"#112233"};
In the chrome debugger, nothing after this line is getting processed.
What am I doing wrong, and how should I do what I am trying to do?
As Chowlett says in comments, you should use erb syntax: <%= "#112233" %>
Next step is get that value from db. If this color value is application-wide, probably you are looking for settings in db solution. I use rails-settings-cached gem for that. Your result code will looks like
color: <%= Setting.foo_color %>
If you are using assets on production, don't forget to recompile them after each setting change.
And if it's not a setting but probably something specific to each user then you can't use application-wide css files for that, but you can write inline css in views.
<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'm getting the following error with my Ruby 1.9 & Rails 2.3.4. This happens when user submits a non-ASCII standard character.
I read a lot of online resources but none seems to have a solution that worked.
I tried using (as some resources suggested)
string.force_encoding('utf-8')
but it didn't help.
Any ideas how to resolve this? Is there a way to eliminate such characters before saving to the DB? Or, is a there a way to make them show?
For ruby 1.9 and Rails 3.0.x, use the mysql2 adapter.
In your gemfile:
gem 'mysql2', '~> 0.2.7'
and update your database.yml to:
adapter: mysql2
http://www.rorra.com.ar/2010/07/30/rails-3-mysql-and-utf-8/
I don't know much about Ruby (or Rails), but I imagine the problem is caused by a lack of control over your character encodings.
First, you should decide which encoding you're storing in your database. Then, you need to make sure to convert all text to that encoding before storing in the database. In order to do that, you first need to know which encoding it is to begin with.
One often repeated piece of advice is to decode all input from whatever encoding it uses, to unicode (if your language supports it) as soon as possible after you get control of it. Then you know that all the text you handle in your program is unicode. On the other end, encode the text to whatever output-encoding you want as a last step before outputting it.
The key is to always know which encoding a piece of text is using at any given place in your code.