Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Cannot call method 'charAt' of undefined

I have a Rails app getting the following error:

Less::ParseError in Home#index

Showing /Users/burtondav/sites/requestsys/app/views/layouts/application.html.erb where line #20 raised:

Cannot call method 'charAt' of undefined
  (in /Users/burtondav/sites/requestsys/app/assets/stylesheets/bootstrap_and_overrides.css.less)
Extracted source (around line #20):

17:       }
18:   </style>
19: 
20:   <%= stylesheet_link_tag "application", :media => "all" %>

Some GEMS I'm using:

gem 'rails', '3.2.11'
gem 'twitter-bootstrap-rails'
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'less-rails'
  gem 'commonjs'
  gem 'therubyracer', :platforms => :ruby
  gem 'uglifier', '>= 1.0.3'

end

It seems to be a problem with LESS that Bootstrap uses.

I've read several other similar issues. So, I upgraded Ruby to 1.9.3p374. But, that didn't fix the problem.

Any ideas?

THANKS!

UPDATE

This is the bootstrap_and_overrides.css.less

@import "twitter/bootstrap/bootstrap";
@import "twitter/bootstrap/responsive";

// Set the correct sprite paths
@iconSpritePath: asset-path("twitter/bootstrap/glyphicons-halflings");
@iconWhiteSpritePath: asset-path("twitter/bootstrap/glyphicons-halflings-white");
like image 651
Reddirt Avatar asked Feb 03 '13 17:02

Reddirt


3 Answers

I have temporary fixed the issue. There is a syntax change to the mixins.less that seems to only be supported by LESS.js

As an example:

Post-2.3 release:

.offsetX (@index) when (@index > 0) {
  .offset@{index} { .offset(@index); }
  .offset@{index}:first-child { .offsetFirstChild(@index); }
  .offsetX(@index - 1);
}

Pre-2.3 release

.offsetX (@index) when (@index > 0) {
  (~'.offset@{index}') { .offset(@index); }
  (~'.offset@{index}:first-child') { .offsetFirstChild(@index); }
  .offsetX(@index - 1);
}

After adding (~"") back in everywhere it was removed (you will have to view a diff from 2.3 and the release before to see where its been removed, all my assets compile again with no errors and still using LESS.

This change was only in mixins.less btw and only about a total of 5 or 6 lines.

like image 96
Mark Avatar answered Oct 26 '22 18:10

Mark


Got the same failure. Fixed it by rolling back twitter-bootstrap-rails to version 2.1.4 (as of this writing the latest is 2.2.4)

# Gemfile
...

group :assets do
  ...

  gem "therubyracer"
  gem "less-rails"
end

gem "twitter-bootstrap-rails", '2.1.4'
like image 20
artemave Avatar answered Oct 26 '22 20:10

artemave


After following up with you in the comments. It seems the answer lies in opening a github issue with either twitter-bootstrap-rails or less-rails describing your issue. You could also follow on the original issue: https://github.com/seyhunak/twitter-bootstrap-rails/issues/72

Otherwise two solutions are offered to you:

  1. Use the SASS version: https://github.com/jlong/sass-twitter-bootstrap
  2. Use the native css version available on their site: http://twitter.github.com/bootstrap/customize.html
like image 39
mathieugagne Avatar answered Oct 26 '22 18:10

mathieugagne