JSON error with coffeescript & Rails asset pipeline - ruby-on-rails

I am using Rails 3.2.14 without issue...
I have recently renamed application.js to application.js.coffee and am now getting a JSON error.
JSON::GeneratorError
only generation of JSON objects or arrays allowed
(in /.../app/assets/javascripts/application.js.coffee)
Even when I delete all the contents of application.js.coffee I still get the error.
When I try to view it directly (http://localhost:3000/assets/application.js), its the same issue:
throw Error("JSON::GeneratorError: only generation of JSON objects or arrays allowed\n (in /.../app/assets/javascripts/application.js.coffee)")
I have combed my app for any potential issues but everything looks pretty standard.

I had a similar problem (Rails 4 asset pipeline throws "only generation of JSON objects or arrays allowed"), which had nothing to do with application.js. The multi_json gem got updated from 1.7.8 to 1.7.9, and broke my app. Any change to the cofeescript-files resulted in this "only generation of JSON objects or arrays allowed" error.
I explicitly put the multi_json gem in my Gemfile, fixed to version 1.7.8. In solved the problem for me.

I have the save issue not in a Rails project, but a ruby project using sprockets.
I have not finally determined the problem, but it seems to be related to execjs and the Javascript runtime used.
You can try to add
gem 'therubyracer'
to your Gemfile. This installs the v8 engine, which solved the problem for me.

Related

Add Hotwire to existing Rails 6.1 app using sprockets

I'm trying to upgrade an existing Rails 6.1 with sprockets app to use stimulus. I installed
gem 'importmap-rails'
gem 'hotwire-rails'
The javascript_importmap_tags causes this error in Firefox Developer Tools:
Uncaught TypeError: Error resolving module specifier “application”. Relative module specifiers must start with “./”, “../” or “/”.
Should this work alongside sprockets?
I have importmap-rails (0.7.6), stimulus-rails (0.4.2)
Error can be safely ignored I believe.
Update: I can confirm that this error can safely be ignored, it doesn't cause any issues. Obviously this is not the ideal "solution", hence the downvote I guess, so if anyone knows a better answer and posts it that will be great and I will mark it as the accepted answer.

Issue adding Bootstrap on Ruby on Rails Project

This is what I followed in order to get started with bootstrap on Ruby on Rails.
I followed every step exactly the same. However, I keep running into the same error for some reason. When I do not do any thing (i.e. do not use bootstrap) everything works (but the application looks trashy).
Whenever I use bootstrap, I get:
invalid regexp character
This is the application trace:
(execjs):24299
app/views/layouts/application.html.erb:8:in `_app_views_layouts_application_html_erb__337612969_59863020'
I have no clue what is happening.
P.S. I am a beginner. So if the solution is simple then, yeah...
remove #gem 'duktape' from gem file..the issue will be solved

Rails 4 asset pipeline throws "only generation of JSON objects or arrays allowed"

This may be related to JSON error with coffeescript & Rails asset pipeline
I'm working on an app in Rails 4. I have an asset called tasks.js.coffee. Until recently everything was fine. This morning I wanted to make a change, and Rails throws "only generation of JSON objects or arrays allowed".
It seems that any change is sufficient to throw the error, even removing a blank line, or changing a single character in a string. When I revert changes it works again.
I'm assuming some gems got updated yesterday when I did a bundle update, causing this problem.
Did anybody else see it? Does anyone know what causes this problem, and how to fix it?
I had to set the execjs version in the Gemfile to 1.4.0: gem 'execjs' '1.4.0'. The recent update to 2.0.0 seems to be the one causing the issue.
Update your ruby version to 2.0.0.

Rails currency exchange gem that works?

Just wondering if anyone has used a currency exchange ruby gem that gets exchange rates from an external api and actually works. I have tried the following gems but have not been able to get any of them to function as described:
goog_currency, yahoo_currency, google_currency, yahoo_finance_currency
One of these uses deprecated code and hence does not work correctly.
I am just trying to display a currency exchange rate in a rails view which has been grabbed from an external api.
I have also considered trying to parse the json from yahoo/google finance urls but this seems much harder to do than it should.
I picked google_currency from your list as most popular and it has been recently maintained. It worked fine for me, I ran the code from the synopsis without a problem.
If you saw the message:
You are using an old or stdlib version of json gem
Please upgrade to the recent version by adding this to your Gemfile:
gem 'json', '~> 1.7.7'
Then you may need to update your copy of multi_json to avoid the json deprecation warnings:
gem install json
gem install multi_json
Which should (at the time of writing) install json 1.8.0 and multi_json 1.7.8. Or of course, if this is for a project, you should be able to pick these versions in your Gemfile, provided there is no conflict with other libraries in your project. The message may of caused you concern, but it is not a problem with google_currency.
I didn't notice any conflict or problems with the google_currency gem, using either the deprecated JSON modules or the most recent ones. To do something similar to what you want:
require 'money'
require 'money/bank/google_currency'
bank = Money::Bank::GoogleCurrency.new
bank.get_rate(:GBP, :USD).to_f
=> 1.5513

Rails 2.3.8 tiny mce issue - undefined method `uses_tiny_mce'

I am facing an issue in my application with tiny mce.
All the gem version & ruby version is OK on my system, but it is giving me error
= undefined method `uses_tiny_mce'
Here i installed the tiny_mce gem. COnfigured it correctely, but still there is an issue.
Please help.
Did you include
config.gem 'tiny_mce'
in config/environment.rb?
I have used this gem in the past too, but have stopped using it. I figured it complicated the setup and deployment of my Rails apps. Since then I have just used the TinyMCE editor by itself. Since it is 100% javascript, it does not touch any Ruby code which keeps things better organized.
I was not using this as a plugin.
I have followed the steps given in the,
http://enginey.googlecode.com/svn/trunk/vendor/plugins/tiny_mce/README.rdoc
Steps :
script/plugin install git://github.com/kete/tiny_mce.git
rake tiny_mce:install
my issue got resolved.

Resources