'rails console' command throwing error in Rails 3.2.9 - ruby-on-rails

I am using Rails 3.2.9 with ruby 1.9.3 (made default using RVM). From the root directory of my test_app when I executed the command 'rails console' / 'rails c', the following error is showing.
rails console
/home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327/gems/execjs-1.4.0/lib/execjs.rb:4:in `<top (required)>'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `<top (required)>'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `require'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `each'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:66:in `block in require'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `each'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327#global/gems/bundler-1.2.3/lib/bundler/runtime.rb:55:in `require'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327#global/gems/bundler-1.2.3/lib/bundler.rb:128:in `require'
from /home/local/rajesh.co/Rajesh/blog/config/application.rb:7:in `<top (required)>'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands.rb:39:in `require'
from /home/local/rajesh.co/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.9/lib/rails/commands.rb:39:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Can anyone help me to resolve this?

Yes, I got the answer for my question.
Just Open the file 'Gemfile' inside the root directory of your application folder, and then paste the below lines there.
gem 'execjs'
gem 'libv8'
gem 'therubyracer'
After pasting it, just save the file and execute 'bundle update' on the command prompt.
On finishing bundle update successfully, you try running 'rails c' or 'rails console' for taking the rails console. It works!!
Thank you.

Install the folowing both:
gem 'execjs'
gem 'therubyracer'

Try installing
gem 'therubyracer'
Source

Related

I can´t run server in Ubuntu 14.02 with ruby 2.2.2 and Rails 4

I´ve a problem when run Rails server. I just installed gem server, but still not working. I am new to the world of programming . I am grateful to anyone who can help me.
Copy an image of the error: http://i.stack.imgur.com/wS7oS.png.
/home/hugo/.rvm/gems/ruby-2.2.2/gems/activesupport-4.0.5/lib/active_support/values/time_zone.rb:283: warning: circular argument reference - now
/home/hugo/.rvm/gems/ruby-2.2.2/gems/execjs-2.5.2/lib/execjs/runtimes.rb:48:in `autodetect': Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/execjs-2.5.2/lib/execjs.rb:5:in `<module:ExecJS>'
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/execjs-2.5.2/lib/execjs.rb:4:in `<top (required)>'
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/uglifier-2.7.1/lib/uglifier.rb:3:in `require'
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/uglifier-2.7.1/lib/uglifier.rb:3:in `<top (required)>'
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.2/lib/bundler/runtime.rb:76:in `require'
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.2/lib/bundler/runtime.rb:72:in `each'
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.2/lib/bundler/runtime.rb:72:in `block in require'
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.2/lib/bundler/runtime.rb:61:in `each'
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.2/lib/bundler/runtime.rb:61:in `require'
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.2/lib/bundler.rb:133:in `require'
from /home/hugo/pin_board/config/application.rb:7:in `<top (required)>'
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/railties-4.0.5/lib/rails/commands.rb:74:in `require'
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/railties-4.0.5/lib/rails/commands.rb:74:in `block in <top (required)>'
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/railties-4.0.5/lib/rails/commands.rb:71:in `tap'
from /home/hugo/.rvm/gems/ruby-2.2.2/gems/railties-4.0.5/lib/rails/commands.rb:71:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
This seems like a similar question to ExecJS and could not find a JavaScript runtime. The resolution here was to ensure NodeJS was installed on the machine:
sudo apt-get install nodejs
uncomment
gem 'therubyracer', platforms: :ruby
in your Gemfile.
Please do
bundle install
after adding 'therubyracer' gem

Activated Ruby RAKE 10.0.1, require 10.0.0

I get this error when i try to run "rake test":
avery#ubuntu:~/rails_projects/depot$ rake test
rake aborted!
You have already activated rake 10.0.1, but your Gemfile requires rake 10.0.0. Using bundle exec may solve this.
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/bundler-1.2.2/lib/bundler/runtime.rb:31:in `block in setup'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/bundler-1.2.2/lib/bundler/runtime.rb:17:in `setup'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/bundler-1.2.2/lib/bundler.rb:116:in `setup'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/bundler-1.2.2/lib/bundler/setup.rb:7:in `<top (required)>'
/home/avery/rails_projects/depot/config/boot.rb:6:in `<top (required)>'
/home/avery/rails_projects/depot/config/application.rb:1:in `<top (required)>'
/home/avery/rails_projects/depot/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)
when i try running "bundle exec rake" i get:
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/execjs-1.4.0/lib/execjs.rb:4:in `<top (required)>'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `<top (required)>'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/bundler-1.2.2/lib/bundler/runtime.rb:68:in `require'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/bundler-1.2.2/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/bundler-1.2.2/lib/bundler/runtime.rb:66:in `each'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/bundler-1.2.2/lib/bundler/runtime.rb:66:in `block in require'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/bundler-1.2.2/lib/bundler/runtime.rb:55:in `each'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/bundler-1.2.2/lib/bundler/runtime.rb:55:in `require'
/home/avery/.rvm/gems/ruby-1.9.3-p327/gems/bundler-1.2.2/lib/bundler.rb:128:in `require'
/home/avery/rails_projects/depot/config/application.rb:7:in `<top (required)>'
/home/avery/rails_projects/depot/Rakefile:5:in `require'
/home/avery/rails_projects/depot/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)
how can i fix this?
You probably have rake 10.0.0 in your Gemfile.lock.
Removing Gemfile.lock might solve the problem.
For the first part of the question: I ran into the same problem and solved it with a:
gem regenerate_binstubs
after that
gem -V
reveals 10.0.0 again.
Answer of 1st query
In your Gemfile, explicitly set the latest rake version by
gem 'rake', '~> 10.0.1'
And then run
$ bundle update rake
Answer of 2nd query
put this in your Gemfile and run bundle install
gem 'therubyracer'
For the second part of the question, you just need to add this to your Gemfile:
gem 'therubyracer'
If you've specified a rake version in your Gemfile that your project requires, eg:
gem 'rake', '~> 10.0.0'
Try installing it again
bundle install

gem installation ok but not with bundle

I am trying to install the pusher-client gem.
I've put this in my Gemfile:
gem "pusher-client",:git=>"git://github.com/logankoester/pusher-client.git"
bundle install is ok
But when I start the app:
/Users/thomas/.rvm/gems/ruby-1.9.2-p318/gems/bundler-1.2.0/lib/bundler/runtime.rb:76:in `require': no such file to load -- pusher/client (LoadError)
from /Users/thomas/.rvm/gems/ruby-1.9.2-p318/gems/bundler-1.2.0/lib/bundler/runtime.rb:76:in `rescue in block in require'
from /Users/thomas/.rvm/gems/ruby-1.9.2-p318/gems/bundler-1.2.0/lib/bundler/runtime.rb:62:in `block in require'
from /Users/thomas/.rvm/gems/ruby-1.9.2-p318/gems/bundler-1.2.0/lib/bundler/runtime.rb:55:in `each'
from /Users/thomas/.rvm/gems/ruby-1.9.2-p318/gems/bundler-1.2.0/lib/bundler/runtime.rb:55:in `require'
from /Users/thomas/.rvm/gems/ruby-1.9.2-p318/gems/bundler-1.2.0/lib/bundler.rb:128:in `require'
from /Users/thomas/Documents/TweetTv/server/tvtweet/config/application.rb:12:in `<top (required)>'
from /Users/thomas/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.1.0/lib/rails/commands.rb:38:in `require'
from /Users/thomas/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.1.0/lib/rails/commands.rb:38:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
It seems to be linked to the - in the gem name, but other gem install correctly.
Any help or suggestion greatly appreciate...
Your git path is wrong. If you go to the repository on GitHub you'll see the code has moved to here.
You should do this in your Gemfile instead:
gem 'pusher-client', :git => "git://github.com/pusher/pusher-ruby-client.git"

Getting error in "rails s", server is not running

It's Rails 3.1.0
What I did:
rails new site
cd site
rails s
The message I got:
/home/user1/.rvm/gems/ruby-1.9.2-p180/gems/execjs-1.2.9/lib/execjs/runtimes.rb:47:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/execjs-1.2.9/lib/execjs.rb:5:in `<module:ExecJS>'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/execjs-1.2.9/lib/execjs.rb:4:in `<top (required)>'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/coffee-rails-3.1.1/lib/coffee-rails.rb:1:in `require'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/coffee-rails-3.1.1/lib/coffee-rails.rb:1:in `<top (required)>'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `require'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.21/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `each'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.21/lib/bundler/runtime.rb:66:in `block in require'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `each'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.21/lib/bundler/runtime.rb:55:in `require'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.21/lib/bundler.rb:122:in `require'
from /home/user1/social/config/application.rb:7:in `<top (required)>'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/commands.rb:52:in `require'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/commands.rb:52:in `block in <top (required)>'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/commands.rb:49:in `tap'
from /home/user1/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0/lib/rails/commands.rb:49:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Why did I get this error?
Can anyone give hint to fix it?
You may also need to install node.js (helped for me)
As the error mentions, you do not have a Javascript runtime installed. You should pick one yourself.
Add this to your Gemfile:
gem "therubyracer"
Then run bundle install and try again.
$sudo apt-get install nodejs
worked for me...
Just Open the file 'Gemfile' inside the root directory of your application folder, and then paste the below lines there.
gem 'execjs'
gem 'libv8'
gem 'therubyracer'
After pasting it, just save the file and execute 'bundle update' on the command prompt.
On finishing bundle update successfully, you try running 'rails s'. It works!!
Thank you.
By seeing your question, your system complains about the lack of JavaScript runtime.
you should visit https://github.com/sstephenson/execjs for a list of possibilities.
I would suggest you to download node.js from this http://nodejs.org/.
follow this way:
cd *your download dir*
tar xvf node-v0.4.11.tar.gz
cd node-v0.4.11
./configure
make
sudo make install
I am giving this answer because this works for me.
This answer will helpful to you.

problem on setting up ruby on rails

I just started learning ruby on rails with "Lynda Ruby on Rails 3 Essential Training".
I finished the installation, and created rails application by writing- "rails new app".
After that when I wrote - "rails server", that's what I saw:
C:\Users\Oded\sites\simple_cms>rails server
C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/mysql2.r
b:2:in `require': 193: %1 is not a valid Win32 application. - C:/Ruby192/lib/r
uby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/mysql2/1.9/mysql2.so (LoadError
)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/my
sql2/mysql2.rb:2:in `<top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/my
sql2.rb:7:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-0.2.6-x86-mingw32/lib/my
sql2.rb:7:in `<top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runti
me.rb:64:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runti
me.rb:64:in `block (2 levels) in require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runti
me.rb:62:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runti
me.rb:62:in `block in require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runti
me.rb:51:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runti
me.rb:51:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler.rb:11
2:in `require'
from C:/Users/Oded/sites/simple_cms/config/application.rb:7:in `<top (re
quired)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/comman
ds.rb:28:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/comman
ds.rb:28:in `block in <top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/comman
ds.rb:27:in `tap'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/comman
ds.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Can you please help me find the solution?
Happy holidays,
Oded
Looks like you're missing some gems! try running bundle install... then all should work.
EDIT: make sure that your Gemfile contains the line
gem 'mysql'
before running bundle install. Bundler will get you set up for mysql, dependencies and all.
You have to go to this website and follow the directions ...
http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/
or in short download the connector mentioned in the article from mysql or a mirror site
Run this command:
gem install mysql --platform=ruby -- --with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32
Make sure you have the correct path to the mysql connector folder that has no spaces!!
After that is complete make sure you copy the libmysql.dll file from the connector library you unzipped and downloaded and placed that in the Ruby\bin file.
After that delete the connector libary and start it up by typing 'rails server' making sure your gem file has the line gem 'mysql' or gem 'mysql2' I'm not sure which one so try both. It sucks and they really need to fix this for windows.

Resources