Please note that User Registration has been temporarily disabled due to a recent increase in automated registrations. If anyone needs an account, please request one here: RequestAccount. Thanks for your patience!--Wmat (talk)
Please email User:Wmat if you experience any issues with the Request Account form.

Difference between revisions of "RPi Ruby on Rails"

From eLinux.org
Jump to: navigation, search
m (libreadline6 already installed by default)
m (Removed more packages already installed)
Line 18: Line 18:
 
  # Additional Ruby dependencies
 
  # Additional Ruby dependencies
 
  sudo apt-get install openssl libreadline6-dev git-core zlib1g libssl-dev libyaml-dev libsqlite3-dev sqlite3
 
  sudo apt-get install openssl libreadline6-dev git-core zlib1g libssl-dev libyaml-dev libsqlite3-dev sqlite3
  sudo apt-get install libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison
+
  sudo apt-get install libxml2-dev libxslt-dev autoconf automake libtool bison
  
 
Now we can use RVM straight from github using:
 
Now we can use RVM straight from github using:

Revision as of 07:21, 30 April 2012

Installing Ruby on Rails on Raspberry Pi

This guide is aimed at developers, although it can be used by beginners if they know what they are after. It is provided as neither Ruby or Rails are included as standard in Debian "squeeze". Other Linux RPi distributions may contain these by default.

THE GUIDE IS STILL DRAFT; AND CAN HOPEFULLY BE OPTIMISED.

Start with a clean image of Debian "squeeze". There is not enough room on a standard 2Gb image. I tested with an 8Gb image, but you may get away with 4Gb.

The installation was all done from the basic (pre startx) command prompt.

This method uses the Ruby Version Manager (RVM), so first we must install all its prerequisites:

# Install prerequisites
sudo apt-get install -y git curl zlib1g-dev subversion

The above is enough to procede, but we will also need the following later, so whilst we're in the mood for apt-getting:

# Additional Ruby dependencies
sudo apt-get install openssl libreadline6-dev git-core zlib1g libssl-dev libyaml-dev libsqlite3-dev sqlite3
sudo apt-get install libxml2-dev libxslt-dev autoconf automake libtool bison

Now we can use RVM straight from github using:

curl -L get.rvm.io | bash -s stable --rails

Note: With my default Debian image and keyboard map, it was very hard to get a | (pipe) character. I got it by pressing AltGr+|

When run, you will get some messages about requirements for Ruby. You need to press 'q'. Note the computer may not react straight away as it is 'thinking'. After a few seconds, the script will download and compile ruby 1.9 and Rails. This takes a long time! (3 Hrs) Have a sleep and check in the morning.

Now you should have ruby:

pi@raspberrypi:~$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [armv61-linux-eabi]

And you should have a rails command:

pi@raspberrypi:~$ rails -v
Rails 3.2.3

Open SSL

Despite having openssl installed, ruby seems to have a problem seeing it. I think this is a common linux problem. The following worked for me, but means waiting a few more hours.

pi@raspberrypi:~$ rvm reinstall 1.9.3 --with-openssl-dir=/usr/bin

JavaScript

Rails requires a JavaScript runtime. Any of the following listed here will do. I installed node.js using this blog by Tom Gallacher. (Note I had to use sudo when doing make install)

Testing Installation

In order to test the installation, let's create a simple project. In this example the name for our new project is school.

pi@raspberrypi:~$ rails new school
pi@raspberrypi:~$ cd school
pi@raspberrypi:~$ rails g scaffold Pupil name:string form:string
pi@raspberrypi:~$ rake db:migrate
pi@raspberrypi:~$ rails s

All being well you will now have a running server with database back end, which you can point a browser at.

Note: You can't use 'class' as a field name, so I chose 'form'.

If you do the above in an X-windows terminal, then point the Raspberry-Pi browser to:

http://0.0.0.0:3000/pupils

You should then be able to Create, Read, Update & Delete (Often called CRUD) pupil records in your database.

Alternatively, if you have another computer on the same network, you can point its browser at the RPi substituting the 0.0.0.0 in the above address for the real RPi one. If you don't know the address of your RPi, then use the following command in a terminal:

ip addr