Sunday, September 18, 2011

Ruby/Rails Setup

Setting up Ruby on Windows

http://www.richardlawrence.info/2011/08/20/getting-started-with-ruby-cucumber-and-capybara-on-windows/


Download Ruby*.exe from: http://rubyinstaller.org/downloads/
Download devkit*.exe from: http://rubyinstaller.org/downloads/
Follow instructions here: https://github.com/oneclick/rubyinstaller/wiki/Development-Kit
ruby dk.rb init
ruby dk.rb install 
gem install rdiscount --platform=ruby
ruby -rubygems -e "require 'rdiscount'; puts RDiscount.new('**Hello RubyInstaller**').to_html"

gem install bson_ext --platform=ruby


Cucumber
Download AnsiCon: http://adoxa.110mb.com/ansicon/index.html
Run c:\opt\ansi140\x64\ansicon -i

gem install cucumber
gem install capybara
gem install rspec
Install FireBug: http://www.getfirebug.com/




JRuby
http://jruby.org/download
http://stackoverflow.com/questions/2762086/getting-jruby-to-work-in-rubymine




Setting up Rails on Windows 
gem install rails http://rubyonrails.org/download
To get around "file 'lib' not found" error: http://help.rubygems.org/discussions/problems/304-file-not-found-lib
  • Didn't work: gem install rdoc
  • Worked: gem install rails --no-ri --no-rdoc

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

gem update --system



RubyMine
http://www.jetbrains.com/ruby/
http://stackoverflow.com/questions/2762086/getting-jruby-to-work-in-rubymine
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.

Demo: http://www.jetbrains.com/ruby/demos/rubymine_7_minutes.zip
Tools -> Load Rake Tasks
    ERROR: uninitialized constant Rake::DSL
http://stackoverflow.com/questions/6085610/ruby-on-rails-and-rake-problems-uninitialized-constant-rakedsl
rake --version
    rake, version 0.8.7
bundle update rake
bundle show rake
    C:/opt/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2
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)


http://localhost:3000/ideas



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/ideas.js.coffee)

Server stack trace in RubyMine:
ActionView::Template::Error (䌧尺坜湩潤獷屜祓瑳浥㈳屜獣牣灩⹴硥履‧獩渠瑯爠捥杯楮敺⁤獡愠湩整湲污漠⁲硥整湲污挠浯慭摮ബ漊数慲汢⁥牰杯慲牯戠瑡档映汩⹥਍
  (in C:/dev/RubymineProjects/Notebook/app/assets/javascripts/ideas.js.coffee)):
    3:
    4:   Notebook
    5:   <%= stylesheet_link_tag    "application" %>
    6:   <%= javascript_include_tag "application" %>
    7:   <%= csrf_meta_tags %>
    8:
    9:
  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 https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
sudo gem install execjs
sudo gem install therubyracer
      same problem
http://stackoverflow.com/questions/6282307/rails-3-1-execjs-and-could-not-find-a-javascript-runtime
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
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
    Success!
http://localhost:3000/
 
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: https://github.com/gmate/gmate

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