ruby tutorial to launch my app - ruby-on-rails

i'm just starting with an Unix based OS
i installed RVM to do the same basic tutorial like windows(dos), but i get
an error, i tried to do the same work in root/user shell but is the same
when i run rails server i get this message:
/usr/local/rvm/gems/ruby-2.0.0-p247/gems/execjs-2.0.1/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 /usr/local/rvm/gems/ruby-2.0.0-p247/gems/execjs-2.0.1/lib/execjs.rb:5:in `<module:ExecJS>'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/execjs-2.0.1/lib/execjs.rb:4:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/uglifier-2.2.1/lib/uglifier.rb:3:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/uglifier-2.2.1/lib/uglifier.rb:3:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
from /home/raul/blog/config/application.rb:7:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:76:in `require'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:76:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
from /usr/local/rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
i reviwed the gem command and dome problems was founded too. Execjs is installed several times in my machine, root->user. This is what i get with gem check:
json-1.8.0.gem has 12 problems
ext/json/ext/generator/.RUBYARCHDIR.time:
Extra file
ext/json/ext/generator/Makefile:
Extra file
ext/json/ext/generator/generator.o:
Extra file
ext/json/ext/generator/generator.so:
Extra file
ext/json/ext/generator/siteconf20130920-14093-1b8hzo9.rb:
Extra file
ext/json/ext/parser/.RUBYARCHDIR.time:
Extra file
ext/json/ext/parser/Makefile:
Extra file
ext/json/ext/parser/parser.o:
Extra file
ext/json/ext/parser/parser.so:
Extra file
ext/json/ext/parser/siteconf20130920-14093-zefm93.rb:
Extra file
lib/json/ext/generator.so:
Extra file
lib/json/ext/parser.so:
Extra file

Just add a JavaScript runtime to your Gemfile (for example, execJS): gem 'execjs'
Then, just run bundle install and it should work.

Install node
sudo apt-get install nodejs
followed by
gem install execjs
or just put gem 'execjs' in your gemfile.
EDIT: i'm editing my answer based on your edits and comments.

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

When I try the command rails server on a new project I get this error

I am running Debian 7. I am using RVM. I am also running mySQL. I am new to ruby in general as well as rails. Please excuse any of me if I seem naive at all.
I setup a project with:
rails new projectname -d mysql
Then I went into that directory and ran:
rails server
I then get this error:
/home/user/.rvm/gems/ruby-2.0.0-p247/gems/execjs-2.0.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/user/.rvm/gems/ruby-2.0.0-p247/gems/execjs-2.0.0/lib/execjs.rb:5:in `'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/execjs-2.0.0/lib/execjs.rb:4:in `'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
from /home/user/htdocs/simple_cms/config/application.rb:7:in `'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.14/lib/rails/commands.rb:53:in `require'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.14/lib/rails/commands.rb:53:in `block in '
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.14/lib/rails/commands.rb:50:in `tap'
from /home/user/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.14/lib/rails/commands.rb:50:in `'
from script/rails:6:in `require'
from script/rails:6:in `'
I went to the link that was provided: https://github.com/sstephenson/execjs
The Read Me under Install says:
gem install execjs
I do this and still get the same error. I am lost.
You have to first install a Javascript runtime, such as Node.js.
For Debian, there's installation instructions on Node.js Github
Edit: The ExecJS README lists the supported Javascript runtimes.
I did install therubyracer. I put the necessary gems insides the projects gem file. This seems to have solved this issue.

javascript runtime error with `rails s` command on remote server

I just set up a VPS to prepare for launching a Rails app and, on the actual remote server, I created a new rails project to test things out, only doing rails new blog -d postgresql. I then tried to start the server using the rails s command and got the error below.
.rvm/gems/ruby-1.9.3-p429#anwalt/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/michael/.rvm/gems/ruby-1.9.3-p429#anwalt/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
from /home/michael/.rvm/gems/ruby-1.9.3-p429#anwalt/gems/execjs-1.4.0/lib/execjs.rb:4:in `<top (required)>'
from /home/michael/.rvm/gems/ruby-1.9.3-p429#anwalt/gems/uglifier-2.1.1/lib/uglifier.rb:3:in `require'
from /home/michael/.rvm/gems/ruby-1.9.3-p429#anwalt/gems/uglifier-2.1.1/lib/uglifier.rb:3:in `<top (required)>'
from /home/michael/.rvm/gems/ruby-1.9.3-p429#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
from /home/michael/.rvm/gems/ruby-1.9.3-p429#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /home/michael/.rvm/gems/ruby-1.9.3-p429#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
from /home/michael/.rvm/gems/ruby-1.9.3-p429#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
from /home/michael/.rvm/gems/ruby-1.9.3-p429#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
from /home/michael/.rvm/gems/ruby-1.9.3-p429#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
from /home/michael/.rvm/gems/ruby-1.9.3-p429#global/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
from /home/michael/blogy/config/application.rb:7:in `<top (required)>'
from /home/michael/.rvm/gems/ruby-1.9.3-p429#anwalt/gems/railties-4.0.0.rc1/lib/rails/commands.rb:78:in `require'
from /home/michael/.rvm/gems/ruby-1.9.3-p429#anwalt/gems/railties-4.0.0.rc1/lib/rails/commands.rb:78:in `block in <top (required)>'
from /home/michael/.rvm/gems/ruby-1.9.3-p429#anwalt/gems/railties-4.0.0.rc1/lib/rails/commands.rb:75:in `tap'
from /home/michael/.rvm/gems/ruby-1.9.3-p429#anwalt/gems/railties-4.0.0.rc1/lib/rails/commands.rb:75:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
I installed $ gem install execjs but still get the same error (I think I have to require it somewhere). Anyways, my question is, why wouldn't the rails s command work on a VPS out of the box the way that it works on a local machine, and, if not using rails s command how am I supposed to start the application once I do launch my real app (rather than this dummy app).
Try to install node.js via apt-get install nodejs or sudo apt-get install nodejs if you are using debian\ubuntu.

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