Learn Rails on Windows, part 1

Background

Ruby on Rails is a very well known framework, inspiring many frameworks created following Rails ways of organizing a web application. The frameworks I have used that are similar to Rails are :
  • In PHP : CakePHP, CodeIgniter, Yii Framework 
  • In Java : Spring Roo
And it seems also being used in Openshift Origin for the implementation of Origin's web console and broker API. That and combined with our need to run Openshift Origin in our private cloud seems a good reason to learn Rails, 

The tutorial

Currently I am following the Ruby on Rails tutorial by Michael Hartl (link). The book strongly encourages using Linux based environment for development, but I am used to work from my Windows machine, so I tried to do development from my Windows Laptop.

Preparation

I installed the x64 version of Ruby 2.0.0 installer in http://rubyinstaller.org/downloads/ for my Windows 8.1 system. I have cases that the 32 bit installer doesn't work for 32-bit Windows XP (I know, this is one ancient platform), the workaround is to use Ruby 1.9.3 instead. 

In order to follow the tutorial, we need to be able to run rails command. Start Ruby command prompt, and install rails.

gem install rails

If you want a specific version of Rails, like me, you can descibe which version you need :

gem install rails -v 3.2.16

We also need bundler :

gem install bundler

Several native plugins requires Ruby Development Kit to be installed (for x64 ruby 2.0, this is DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe ). 
MySQL gem also requires either MySQL connector or MySQL server to be installed, and gem installation needs to refer to the include and lib directories as well :

gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.5\include"' 

Rails template for Origin


I used https://github.com/openshift/rails-example as the starting point of my application. Just use the github url for the reference when creating the application in Origin. But if your private cloud doesn't have access to the internet, then you need to clone and force push :

git clone https://github.com/openshift/rails-example railtest
cd railtest

Install all requirements for your local (i.e. Windows) system  :

D:\SourceCode\www\railtest>bundle install
DL is deprecated, please use Fiddle
Using rake 10.1.0
Using i18n 0.6.9
Using multi_json 1.8.2
Using activesupport 3.2.16
Using builder 3.0.4
Using activemodel 3.2.16
Using erubis 2.7.0
Using journey 1.0.4
Using rack 1.4.5
Using rack-cache 1.2
Using rack-test 0.6.2
Using hike 1.2.3
Using tilt 1.4.1
Using sprockets 2.2.2
Using actionpack 3.2.16
Using mime-types 1.25.1
Using polyglot 0.3.3
Using treetop 1.4.15
Using mail 2.5.4
Using actionmailer 3.2.16
Using arel 3.0.3
Using tzinfo 0.3.38
Using activerecord 3.2.16
Using activeresource 3.2.16
Using coffee-script-source 1.6.3
Using execjs 2.0.2
Using coffee-script 2.2.0
Using rack-ssl 1.3.3
Using json 1.8.1
Using rdoc 3.12.2
Using thor 0.14.6
Using railties 3.2.16
Using coffee-rails 3.2.2
Using jquery-rails 3.0.4
Using minitest 5.1.0
Using mysql2 0.3.14
Using pg 0.17.0
Using bundler 1.8.3
Using rails 3.2.16
Using sass 3.2.12
Using sass-rails 3.2.6
Using sqlite3 1.3.8
Using uglifier 2.3.2
Bundle complete! 11 Gemfile dependencies, 43 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

We could run the local development server using rails server:

D:\SourceCode\www\railtest>rails server
=> Booting WEBrick
=> Rails 3.2.16 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2015-03-07 09:39:34] INFO  WEBrick 1.3.1
[2015-03-07 09:39:50] INFO  ruby 2.0.0 (2014-05-08) [x64-mingw32]
[2015-03-07 09:39:50] INFO  WEBrick::HTTPServer#start: pid=5684 port=3000

Conclusion for Part 1

Running rails in Windows is not an out-of-the box experience, but not so difficult given a lot of clues in StackOverflow.

Comments

Popular posts from this blog

Long running process in Linux using PHP

Reverse Engineering Reptile Kernel module to Extract Authentication code

SAP System Copy Lessons Learned