the ruby teaching edition for macintosh

8
The Ruby Teaching Edition for Macintosh The Ruby Teaching edition for Macintosh is designed to be easily installed on a Macintosh system. This installation also includes the SQLite3 Database Browser (http://sqlitebrowser.sourceforge.net/) to allow us to explore the contents of our SQLite3 databases that we will use with Rails. Note: The Ruby Teaching Edition works on Mac OS/X 10.5 - but Mac OS/X 10.5 already has Ruby and Rails installed - so you may want to simply use the versions of this software that come with Mac OS/X 10.5. If you have Macintosh OS/X 10.5, read the whole document and then see the section on " Using Macintosh OS/X 10.5 Without Installing Ruby Teaching Edition". You can install the Ruby Teaching Edition if you like on Mac OS 10.5 and follow these examples exactly - but you will probably find it more convenient to simply use the built-in ruby and rails commands in Mac OS 10.5. Installing Ruby Teaching Edition for Macintosh Download the latest version from: http://www-personal.umich.edu/~csev/teachrails/downloads/ Extract the file to your desktop - you should end up with a single directory called "rte- mac" - that directory should contain a file named "rsu.sh" and a subdirectory called ruby and hopefully this documentation. This rte-mac directory can be installed anywhere including your Desktop, Home Directory, a Shared File Server, USB drive or a USB stick. A USB stick will be somewhat slow - but may be your only choice in a shared environment. To install - simply move or copy the rte-mac to the desired location. Once you have it installed, continue with the instructions below. Using the Rails Training Environment for the Macintosh These instructions are to be followed anytime you want to start a new application or simply work on an existing application. We will do much of the control of our Rails

Upload: sammy17

Post on 09-May-2015

790 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Ruby Teaching Edition for Macintosh

The Ruby Teaching Edition for Macintosh The Ruby Teaching edition for Macintosh is designed to be easily installed on a Macintosh system. This installation also includes the SQLite3 Database Browser (http://sqlitebrowser.sourceforge.net/) to allow us to explore the contents of our SQLite3 databases that we will use with Rails. Note: The Ruby Teaching Edition works on Mac OS/X 10.5 - but Mac OS/X 10.5 already has Ruby and Rails installed - so you may want to simply use the versions of this software that come with Mac OS/X 10.5. If you have Macintosh OS/X 10.5, read the whole document and then see the section on " Using Macintosh OS/X 10.5 Without Installing Ruby Teaching Edition". You can install the Ruby Teaching Edition if you like on Mac OS 10.5 and follow these examples exactly - but you will probably find it more convenient to simply use the built-in ruby and rails commands in Mac OS 10.5.

Installing Ruby Teaching Edition for Macintosh Download the latest version from: http://www-personal.umich.edu/~csev/teachrails/downloads/ Extract the file to your desktop - you should end up with a single directory called "rte-mac" - that directory should contain a file named "rsu.sh" and a subdirectory called ruby and hopefully this documentation.

This rte-mac directory can be installed anywhere including your Desktop, Home Directory, a Shared File Server, USB drive or a USB stick. A USB stick will be somewhat slow - but may be your only choice in a shared environment. To install - simply move or copy the rte-mac to the desired location. Once you have it installed, continue with the instructions below.

Using the Rails Training Environment for the Macintosh These instructions are to be followed anytime you want to start a new application or simply work on an existing application. We will do much of the control of our Rails

Page 2: The Ruby Teaching Edition for Macintosh

environment through the Macintosh Terminal program. Start the terminal program under Applications -> Utilities -> Terminal. You might want to keep the Terminal program in your Dock by clicking on the terminal icon in the Dock and holding until a menu pops up.

Once the menu pops up select Keep in Dock and the terminal will be available in a single click. Once you are in the terminal, you use the cd command to get into the rte-mac directory. In this Example, the ret-mac directory is on the Desktop. Once you are in the rte-mac directory, type the commands as shown below. The output should be similar.

Once you have checked the ruby, rails, and gem commands. The only steps that are needed are to start the terminal, use cd to get into the rte-mac directory, and type the source rsu.sh command - from that point you can start developing your rails applications.

Page 3: The Ruby Teaching Edition for Macintosh

You can develop your rails applications in any directory you like - in this example, we will simply put them in a directory called rails_apps in the rte-mac directory. The rails command creates a new application as shown in the output below. The application is named "zork" in the example below and stored in a directory named "zork". The "-d sqlite3" indicates that we would like our Rails application to use the SQLite3 database. The rails command creates a large number of files - effectively writing our first application. $ cd Desktop/rte-mac/ $ source rsu.sh Setting up Ruby Environment $ cd rails_apps/ $ rails zork -d sqlite3 create create app/controllers create app/helpers create app/models [ …. Snip …. ] create log/production.log create log/development.log create log/test.log $

Once this is complete, we will go into the newly created "zork" directory and start the Ruby web server for our new application. create log/development.log create log/test.log $ cd zork $ pwd /Users/csev/Desktop/rte-mac/rails_apps/zork $ ruby script/server => Booting Mongrel (use 'script/server webrick' to force WEBrick) => Rails application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server ** Starting Mongrel listening at 0.0.0.0:3000 ** Starting Rails with development environment... ** Rails loaded. ** Loading any Rails specific GemPlugins ** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart). ** Rails signals registered. HUP => reload (without restart). It might not work well. ** Mongrel available at 0.0.0.0:3000 ** Use CTRL-C to stop.

Once this step is completed, you can access your new Rails application by opening a browser and pointing it to http://localhost:3000/

Page 4: The Ruby Teaching Edition for Macintosh

You can click on "About your application's environment" and check to make sure that it is using the sqlite3 database. All that is left is to shut down your web server. To do this we go back to the terminal. You should see some log information as your server was talking to the browser. You can press Control-C in the terminal to abort the web server.

Your test of the Ruby Training Edition for Macintosh is now complete. You can create and run Rails applications. Make sure to do the source rsu.sh command from the rte-mac directory each time you start a new window - or the rails and ruby command will not work properly.

Page 5: The Ruby Teaching Edition for Macintosh

Using RTE for the Macintosh on a USB Stick To install the Ruby Teaching Edition onto a USB Stick, simply copy the rte-mac directory onto the USB stick. You should make sure that the name of your USB stick has no spaces like the USB stick below:

To rename the USB stick gently single click on the words below the stick and it should allow you to change the volume label on the USB Stick. You can name it anything you like - just make sure there are no spaces. When you insert a USB stick into your Macintosh, the drive is mounted under the /Volumes directory using the disk name. So to navigate to the rte-mac directory o the USB stick you simple change to the proper directory as shown below: $ cd /Volumes/NONAME/rte-mac/ $ ls SQLite Database Browser 1.3.app rsu.sh rails_apps rte-mac.pdf readme.txt ruby $ source rsu.sh Setting up Ruby Environment $ rails --version Rails 1.2.6 All of the rest of the operations work the same as if the Ruby Training Edition were installed on your hard disk. Because running from a USB stick is slower - you might want to copy the ret-mac directory onto your desktop each time you work in a shared environment - it is about 60Mb - it takes about 30 seconds to copy. Make sure not to lose your work however when you move form computer to computer - you need to know where your Rails applications have been edited and copy them back to the USB stick before you leave the shared computer.

Using Macintosh OS/X 10.5 Without Installing Ruby Teaching Edition Since Mac OS/X 10.5 has ruby and rails already installed you do not need to download the Ruby Training Edition at all. All of the scenarios above scenarios work:

Page 6: The Ruby Teaching Edition for Macintosh

• You do not have to download and install the Ruby Training Edition • You can develop your rails applications in any directory

• You do not have to use the source rsu.sh command at all

All of the rest of the ruby, gem, and rails commands should simply work. If you do not install the RTE - you will have to manually install the SQLite3 Database Browser (http://sqlitebrowser.sourceforge.net/) by following the directions on that site.

Using jEdit to Edit Ruby Files We will use the jEdit editor (www.jedit.org) to edit our Ruby programs. There are many editors available by jEdit has the advantage that it is completely free and runs the same on Macintosh and PC computers.

Download and install jEdit from www.jedit.org using the instructions provided at the site. On the downloads page, choose the stable edition / Mac OS X Package (jedit42.dmg). Once it downloads and mounts the disk, navigate to fine the jEdit 4.2 folder.

Drag the jEdit 4.2 folder to your Applications directory. You may be asked to type your password to install the software. Then navigate to the Applications directory and open jEdit 4.2 and then click on the jEdit icon.

Page 7: The Ruby Teaching Edition for Macintosh

We need to set a few things to make jEdit easier to use. First, select Utilities -> File System Browser. The browser will pop up. We want to pin the browser to the left side of our jEdit window.

In the File System Browser window, click the small triangle in the upper left of the browsers and select "Dock at Left". From this point forward, you have a file browser on the left of your jEdit interface to allow you to easily switch between files.

Next we will install the Ruby syntax plug-in. Go to Plugins -> Plugin Manager and then select Install. Scroll down until you see the ProjectViewer (it helps to sort by plugin name before scrolling) - select this plugin and install. Once the ProjectViewer has been installed, select the RubyPlugin and install it. The SideKick plugin will automatically be selected.

Page 8: The Ruby Teaching Edition for Macintosh

If jEdit hangs for a long time and does not seem to download a plugin, select Download Options and choose a mirror site close to you and then reattempt the install.

Copyright and Notes This material is Copyright 2007, 2008, Charles Severance - Creative Commons Attribution 2.5. You are welcome to use, reuse, adapt or remix this material in any way you feel useful. If you find mistakes or suggest improvements please contact the author. If you are teaching Rails - I highly recommend this book: Build Your Own Ruby on Rails Web Applications by Patrick Lenz (http://www.sitepoint.com/books/rails1/). Please visit www.rubylearn.com to see if there is updated or additional materials available. I am anticipating a growing community of people who want to teach Ruby and Rails at the High School, and College level - I would like to see us developing and sharing materials as much as possible so we can focus on teaching as well as we can rather than always building materials from scratch individually. Dr. Charles Severance www.dr-chuck.com February 3, 2008