When trying to deploy to heroku I get the following error:
rake aborted!
Uglifier::Error: Unexpected character '“'
I have modified the production.rb to include config.assets.js_compressor = Uglifier.new(harmony: true) instead of config.assets.js_compressor = :uglifier
It seems you have used a typographic (or "smart") quote character somewhere in your code as opposed to a normal " character. Depending on your font, they might look very similar but are different characters, resulting in the error you have seen there.
To resolve this, you should search all of your code and replace all mentions of the “ character with ".
Related
I know there's lots of similar questions but I haven't found a solution yet. I'm trying to use the CSV parsing library with Ruby 1.9.1 but I keep getting:
/usr/lib/ruby/1.9.1/csv.rb:1925:in `block (2 levels) in shift': Illegal quoting in line 1. (CSV::MalformedCSVError)
My CSV files were created in Windows 7 but it's Ubuntu 12.04 that I'm using to run the Ruby script, which looks like this:
require 'csv'
CSV.foreach('out.csv', :col_sep => ';') do |row|
puts row
end
Nothing complicated, just a test, so I assumed it must be the Windows control characters causing problems. Vim shows up this:
"Part 1";;;;^M
;;;;^M
;;;;^M
Failure to Lodge Income Tax Return(s);;;;^M
NAME;ADDRESS;OCCUPATION;"NO OF CHARGES";"FINE/PENALTY £"^M
some name;"some,address";Bookkeeper;3;1,250.00^M
some name;"some,address";Haulier;1;600.00^M
some name;"some,address";Scaffolding Hire;1;250.00^M
some name;"some,address";Farmer;2;500.00^M
some name;"some,address";Builder;2;3000.00
I've tried removing those control characters for carraige returns that Windows added (^M), but %s/^V^M//g and %s/^M//g result in no pattern found. If I run %s/\r//g then the ^M characters are removed, but the same error still persists when I run the Ruby script. I've also tried running set ffs=unix,dos but it has no effect. Thanks.
Update:
If I remove the double quotes around the Part 1 on the first line, then the script prints out what it should and then throws a new error: Unquoted fields do not allow \r or \n (line 10). If I then remove the \r characters, the script runs fine.
I understand that I would have to remove the \r characters, but why will it only work if I unquote the first value?
The problem causing the Illegal quoting error was due to a Byte-Order-Mark (BOM) at the very beginning of the file. It didn't show up in editors, but the Ruby CSV lib was choking on it unless :encoding => 'bom|utf-8' was set.
Once that was fixed, I still needed to remove all the '^M' characters by running %s/\r//g in vim. And everything was working fine after that.
I use preg_match to the program like this
if (preg_match('/^[a-z0-9]+\:/{1,2}', $filename))
But it shows an error like this
Warning: preg_match() [function.preg-match]: Unknown modifier '{'
how to change this?
You are missing '/' at the end of the regex and you should escape '/' in the regex itself. This should work i.e. warning should be gone (ignoring if regex you've written is doing what you want):
if (preg_match('/^[a-z0-9]+\:\/{1,2}/', $filename))
this is my ruby code
require 'json'
a=Array.new
value="¿value"
data=value.gsub('¿','-')
a[0]=data
puts a
puts "json is"
puts jsondata=a.to_json
getting following error
C:\Ruby193>new.rb
C:/Ruby193/New.rb:3: invalid multibyte char (US-ASCII)
C:/Ruby193/New.rb:3: syntax error, unexpected tIDENTIFIER, expecting $end
value="┐value"
^
That's not a JSON problem — Ruby can't decode your source because it contains a multibyte character. By default, Ruby tries to decode files as US-ASCII, but ¿ isn't representable in US-ASCII, so it fails. The solution is to provide a magic comment as described in the documentation. Assuming your source file's encoding is UTF-8, you can tell Ruby that like so:
# encoding: UTF-8
# ...
value = "¿value"
# ...
With an editor or an IDE the soluton of icktoofay (# encoding: UTF-8 - in the first line) is perfect.
In a shell with IRB or PRY it is difficult to find a working configuration. But there is a workaround that at least worked for my encoding problem which was to enter German umlaut characters.
Workaround for PRY:
In PRY I use the edit command to edit the contents of the input buffer
as described in this pry wiki page.
This opens an external editor (you can configure which editor you want). And the editor accepts special characters that can not be entered in PRY directly.
I have a lot of these code lines:
#breadcrumb = []
#breadcrumb << ["#!", "Hladať"]
It was in ruby ree-1.8, but I can change it to 1.9, but I have this error:
/app/controllers/index_controller.rb:36: syntax error, unexpected $end, expecting ']'
#breadcrumb << ["#!", "Hladať"]
When I delete "ť " and others special chars(ľščťžýáí...) it`s ok, but I need these chars.
Add the "magic comment" specifying the encoding to the top of each Ruby file that has non-ASCII characters:
# encoding: UTF-8
This is not needed in Rails view files provided config.encoding is set properly (the default is UTF-8). You should also read more about Ruby 1.9's encoding behavior.
When I was developing my project on my local file I had this line in code which worked correctly:
#json = Location.qty_of_deliv_from(params[:from_rc])
.qty_of_deliv_to(params[:to_rc])
When I deployd with passenger I get a syntax error on this line which goes avay if I have all the code in the same line:
#json = Location.qty_of_deliv_from(params[:from_rc]).qty_of_deliv_to(params[:to_rc])
Is this a known issue?
Perhaps your server's ruby version is different and parses differently?
In any case, in Ruby, when writing multiline code you typically want to make sure your lines to be wrapped are syntactically incomplete, so as not to confuse the parser, e.g. by using a hanging dot, instead.
Location.qty_of_deliv_from(params[:form_rc]).
qty_of_deliv_to(params[:to_rc])
Or you can use the backslash to escape the new line:
Location.qty_of_deliv_from(params[:form_rc]) \
.qty_of_deliv_to(params[:to_rc])