Sunday, September 18, 2011

Ruby/Rails Setup

Setting up Ruby on Windows

Download Ruby*.exe from:
Download devkit*.exe from:
Follow instructions here:
ruby dk.rb init
ruby dk.rb install 
gem install rdiscount --platform=ruby
ruby -rubygems -e "require 'rdiscount'; puts'**Hello RubyInstaller**').to_html"

gem install bson_ext --platform=ruby

Download AnsiCon:
Run c:\opt\ansi140\x64\ansicon -i

gem install cucumber
gem install capybara
gem install rspec
Install FireBug:


Setting up Rails on Windows 
gem install rails
To get around "file 'lib' not found" error:
  • Didn't work: gem install rdoc
  • Worked: gem install rails --no-ri --no-rdoc

> rails new path/to/your/new/application 
> cd path/to/your/new/application 
> rails server

gem update --system

RubyMine does not have any support for Java and does not recognize Java classes - JRuby is only supported as a target platform for running regular Ruby code. Full Java/Ruby interoperability is supported in IntelliJ IDEA with the Ruby plugin.

Tools -> Load Rake Tasks
    ERROR: uninitialized constant Rake::DSL
rake --version
    rake, version 0.8.7
bundle update rake
bundle show rake
rake --version
    rake, version 0.8.7
gem uninstall rake -v=0.8.7
gem install rake -v=0.9.2 
rake --version

    rake, version 0.9.2
RubyMine Database Integration Rails data sources detected, but some additional drivers are required for RubyMine to connect to the database.
    Zentus SQLiteJDBC (v056)


ExecJS::RuntimeError in Ideas#index
Showing C:/dev/RubymineProjects/Notebook/app/views/layouts/application.html.erb where line #6 raised:
  (in C:/dev/RubymineProjects/Notebook/app/assets/javascripts/

Server stack trace in RubyMine:
ActionView::Template::Error (䌧尺坜湩潤獷屜祓瑳浥㈳屜獣牣灩⹴硥履‧獩渠瑯爠捥杯楮敺⁤獡愠湩整湲污漠⁲硥整湲污挠浯慭摮ബ漊数慲汢⁥牰杯慲牯戠瑡档映汩⹥਍
  (in C:/dev/RubymineProjects/Notebook/app/assets/javascripts/
    4:   Notebook
    5:   <%= stylesheet_link_tag    "application" %>
    6:   <%= javascript_include_tag "application" %>
    7:   <%= csrf_meta_tags %>
  app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___633557058_33725952'
  app/controllers/ideas_controller.rb:7:in `index'

Can't read Chinese... giving up.

turning to...

Getting Started with Rails

rails new blog
cd blog
rake db:create
rake -T
rails server
rails generate controller home index
del public\index.html
edit config\routes.rb
    root :to => "home#index"

Same Chinese error message... "Learn Mandarin" now on my todo list...

Turning to Linux Ubuntu

Setting up Ruby and Rails on Ubuntu

sudo apt-get install ruby-full build-essential
sudo apt-get aptitude 
sudo aptitude install ruby build-essential libopenssl-ruby ruby1.8-dev
sudo apt-get install rubygems 
sudo gem install rails --no-ri --no-rdoc  (Using same workaround for 'lib' problem)
echo "export PATH=/var/lib/gems/1.8/bin:$PATH" >> .bashrc
mkdir www; cd www 
rails new blog
cd blog
sudo apt-get install libsqlite3-dev
sudo gem install sqlite3-ruby
sudo gem install uglifier
rails server
      /var/lib/gems/1.8/gems/execjs-1.2.7/lib/execjs/runtimes.rb:47:in `autodetect': Could not find a JavaScript runtime. See for a list of available runtimes. (ExecJS::RuntimeUnavailable)
sudo gem install execjs
sudo gem install therubyracer
      same problem
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs 
rails server
rails generate controller home index
del public\index.html
edit config\routes.rb
    root :to => "home#index"
rails generate scaffold Post name:string title:string content:text
rake db:migrate

vi app/views/home/index.html.erb

    <%h1>%Hello, Rails!
    <%/h1>% <%= link_to "My Blog",  posts_path %> 

TextMate for GEdit:

sudo apt-add-repository ppa:ubuntu-on-rails/ppa
sudo apt-get update
sudo apt-get install gedit-gmate