Category Archives: RoR

Using Deliberate Practice in the Classroom

If learning something to professional level takes 10,000 hours, then it’s probably important to make time to practice the skills needed for that profession. It’s up to us as educators to facilitate practice experiences, which help our students do this. To that end, I’ve decided to do one less lecture each week for my course on Ruby on Rails so that there is one lecture a week, and the second ‘lecture’ is a ‘deliberate practice’ session that builds on what was covered in the lecture. This is following Kathy Sierra’s dictum that ‘less is more’. Less lecture means more time to embed what was covered with other activities.

I’m trying to build on the learning experience of a code retreat, which we’ve organised in the past, as well as what comes out of coding katas too, and the discussions I’ve had with developers over the years about how they work and learn. Thanks to all of you.

I’ll not go as far as some to explain how deliberate practice should be a process, or that it leads to enlightened software craftspeople, but rather that it’s part of how you challenge yourself to try different approaches as a way to learn by doing.

Each of these ‘deliberate practice’ sessions follows the same format. Students should work with a partner or two so that no one is working on their own. I set out the topic and point to the github repository that we’ll be using. Then follows three rounds of twelve minutes. At the end of each round we pause, compare notes as to what they did, what posed a challenge, and what they’re going to do next. To wind up the session we go over any take aways. I think, however, that I need to change this to a more reflective approach so that the students think more about what they did, and how they might approach challenges differently in the future.

Each of these sessions is somethign simple and basic. The purpose is to offer lots of practice in the basics of Rails development. Create a new app, write some code for a controller and its views. Create a different app, focus on different types of views. Pull down a repo, then run the migrations, now change the models, controllers and views to make it all work better.

The students seem to like this so far, and I’ll keep working on new scenarios this term, and then revise them for improved outcomes next term. The joy of having a course run each term is this faster feedback cycle. Feel free to get in touch if you have comments, or suggestions about this approach.

Save

Save

Ruby and Rails development of Heroku sites

I’ve been working on a live project recently and found it necessary to see what was happening on the Heroku version as it was running differently from my development machine. Saying ‘it works on my machine’ doesn’t help the people trying to use the site, so I had to delve deeper and work out a routine to ensure I was both finding the problem, and also fixing it correctly.

Oh, it goes without saying, try to get Postgresql running on your dev machine.

The short answer is to use something like the following steps when developing sites to run on Heroku:

a) get code with tests working – be sure to use capybara as this will save you hours of time as you repeatedly run the tests. For this project I was spending about 30 seconds running through a number of tests on the site to see that pages loaded correctly, and forms did what they should do too. Running them by hand would’ve taken at least 15 minutes or longer each time, and I would be so board too.

b) pull down heroku db and add to postgres using pg:pull command
https://devcenter.heroku.com/articles/heroku-postgresql#pg-pull which means you can pull down the postgresql database and install it into your locally running one and then swap out your ‘dev’ database to use this one and see what’s missing, or whatever.

c) add anything new there to file that loads your test, and/or live data into the database.

d) check all runs ok on dev with db from heroku

e) when ok, then load your data into test database

f) upload to heroku – including db data if necessary checking with heroku logs command as needed. This lets you see what fell over and wasn’t running as expected.

Set up Linux box in VirtualBox for Ruby/Rails development

These notes were used on a Windows 7 machine to create an Ubuntu Server and started with the notes created by http://notesofgreg.blogspot.co.uk/2012/04/slim-rails-environment-v2.html who started this after discovering my Vagrant notes didn’t quite get him where he wanted to be with Ruby and Rails development. I started with those and then added more parts as I was doing this behind the proxy and wanted any student to be able to copy what I’ve done to tweak their own version of a Linux box. I also referred to http://munkyonline.co.uk/articles/lamp-ubuntu-server-on-virtualbox for general creating vm and http://www.ubuntu.com/download/help/install-ubuntu-server for ubuntu server ISO.

I rebuilt the server in August 2015 and these notes were updated then.

We use a ‘server’ and not a ‘desktop’ ISO so that this is a smaller installation. Hence we only use a lightweight ‘desktop’ like Fluxbox. We still can use our Windows desktop, so we only need lightweight tools for this virtuarl machine.

Start with ISO

Once you have an ISO you can start it up and install it into VirtualBox.  You will need to set the proxy if at the university so that you can download more software as needed in the box. Just follow the defaults for the most part and let it use the whole partition. Set yourself easy username and password. This is a virtual machine remember so you don’t need to be paranoid. You can also tell it to install Postgresql during this phase too.

When the installation is done and you’ve logged back in again with your new account you can start adding the software you want to use for the application.

(No longer necessary for Aberdeen, but kept here in case you’re doing this somewhere else.) I found you need to set the proxy again for the session with the command:
export https_proxy=http://proxy.abdn.ac.uk:8080

If you need to set the root password then look at https://help.ubuntu.com/community/RootSudo and at
http://ubuntuforums.org/showthread.php?t=1599832 at end of page for running as su with root

This setup uses fluxbox as a lightweight desktop (right-click) for any options. You start the ‘desktop’ from the command line with ‘startx’ command and can right-click for menu options. When you’re done you drop out of the desktop with ‘right-click->exit’.
You can stop the virtual machine with ‘machine->Close and select ‘send Shutdown signal’ ‘so that pick up where left off before.

Installing the system

#System
sudo apt-get update
sudo apt-get install xinit
sudo apt-get install fluxbox
sudo apt-get install build-essential
#Node.js Rails will not run without a Javascript Engine
sudo apt-get install python-software-properties

#might not need next two steps, try setting proxy first, but may need to also run this as su and thus set password for root. Try to avoid that though.
#set password for su
#switch to su and add proxy details so that su knows them.
export http_proxy=http://proxy.abdn.ac.uk:8080

sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

#imagemagick so that we can manipulate images on the server
http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=20814
sudo apt-get install imagemagick libmagick++-dev

#Sqlite3
sudo apt-get install sqlite3 libsqlite3-dev

#Postgres <<– you need this for working with Heroku
sudo apt-get install libpq-dev (you may get some errors and also need to run sudo apt-get update to fix things, persist, it should all work)

#Ruby
We use the details at this Set up Ruby page to set up what we need on our Ubuntu server

#Git for version control
We’ll need version control and for dealing with some installation issues
sudo apt-get install git

#Rails
We use the Rails details at this Set up Ruby page to set up what we need on our Ubuntu server

sudo apt-get install libxml2-dev libxslt-dev (cucumber/nokogiri)
sudo gem install rails –http-proxy http://proxy.abdn.ac.uk:8080
sudo gem install sqlite3 –http-proxy http://proxy.abdn.ac.uk:8080

sudo gem install rspec –http-proxy http://proxy.abdn.ac.uk:8080
sudo gem install rspec-rails –http-proxy http://proxy.abdn.ac.uk:8080

sudo gem install cucumber –http-proxy http://proxy.abdn.ac.uk:8080
sudo gem install cucumber-rails –http-proxy http://proxy.abdn.ac.uk:8080
sudo gem install capybara –http-proxy http://proxy.abdn.ac.uk:8080

sudo gem install rmagick –http-proxy http://proxy.abdn.ac.uk:8080

#Heroku tools for deploying to remote server
heroku toolbelt wget -qO- https://toolbelt.heroku.com/install.sh | sh (note capital letter ‘o’)

#rails new cookbook -T (t flag keeps tests out)
#cd cookbook
#bundle install will get the rest of the gems

##Other Programs
#Terminator (Better terminal)
sudo apt-get install terminator
#scite for editing files
sudo apt-get install scite

#Google Chrome (web Browser) – that is a capital ‘oh’ NOT a zero in command and each ‘sudo’ is a new command
sudo wget -q -O – https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add –
sudo sh -c ‘echo “deb http://dl.google.com/linux/chrome/deb/ stable main” >> /etc/apt/sources.list.d/google.list’
sudo apt-get update
sudo apt-get install google-chrome-stable

#sqlitebrowser (SQLite3 browser)
sudo apt-get install sqlitebrowser

#enable shared folders on machine
Start here for basics https://www.virtualbox.org/manual/ch04.html
This page has the scripts for mounting and running the install script https://mylinuxramblings.wordpress.com/2014/12/06/how-to-install-virtualbox-guest-editions-in-ubuntu-server-14-04/
And then follow on with this post to configure integration http://www.sysprobs.com/virtualbox-shared-folders-ubuntu-1010-guest-windows-7-host

#change permissions on shared folder so default user can use this folder and edit files (edit in Windows on and run commands in Linux)
use this to add ruby to vboxsf folder permissions
sudo adduser xxxxxxx vboxsf
#need to log out and back in again for this to take effect

Winding up

You’re now done and should be able to do all that you need to do in a Linux box on a Windows machine. This should take lots of the pain of Ruby running on Windows away. So that you have a better idea of what you’re doing you should also look to these links for more help:

https://help.ubuntu.com/community/UsingTheTerminal for more on commands

http://fluxbox.org/ for details about the windowing manager installed

you can edit the menu for fluxbox so that Terminator and Scite are included by opening .fluxbox/menu from your home directory and adding in the three lines starting with [exec]. The result just adds them to the end of your menu, so if you want them grouped in another location then follow the instructions at the top of the full menu which is included there under the ‘etc’ directory.
NOTE: For ABDN we don’t need to declare the proxy any longer, but I leave it here in case it helps someone else.

begin] (fluxbox)
[include] (/etc/X11/fluxbox/fluxbox-menu)

[exec] (editor) {scite}
[exec] (console) {terminator}
[exec] (google chrome with proxy) {google-chrome –proxy-server=http://proxy.abdn.ac.uk:8080}
[end]

Look at http://www.makeuseof.com/tag/8-great-alternative-desktop-managers-for-linux/ for alternatives to Fluxbox if it’s too minimalist for you.

You will now have a basic system to run what you need for the AWAD course using ruby and rails. You will need to learn more about using Ubuntu, and linux commands, but this will get you started and provide a system where installation of ruby gems and other tools should go smoothly.

Vagrant set up notes

Vagrant for classroom inspired by

http://www.slideshare.net/ctrabold/2011-1029-ctraboldrailscamphh

https://twitter.com/ctrabold at  the 2011 Hamburg Railscamp http://railscamp-hamburg.de/ which I saw from the twittersteam of the event.

The goal of the project is to setup Vagrant to launch a linux VM that will run Ruby 1.9.2 and Rails 3 for use by students without the attendant issues that accompany them when setting everything up on a Windows machine.

Ryan Bates has much of the details for the process used in his RailsCast on http://railscasts.com/episodes/292-virtual-machines-with-vagrant?view=asciicast but I used a packaged version of Ruby1.9.2 instead of his solution.

http://vagrantup.com/ and then ‘get started’ and ‘documentation’ as needed plus guides on specifics at

http://stackoverflow.com/questions/7859698/installing-ruby-1-9-2-on-ubuntu-using-chef-and-vagrant with details about different options for putting 1.9.2 on the vagrant box

http://www.capsunlock.net/2011/12/vagrant-productivity-developer-sysadmin.html on installing ruby package on box and notions of cookbook recipies

http://linux.about.com/od/ubuntu_doc/a/ubudg21t2.htm for installing .deb packages

Others:

https://gist.github.com/1349431 on setting up own box from scratch and packaging

Solution for now for us is this:

Build base box, add ruby 1.9.2, and then put on requisite gems and other software as needed for the term an then package this as a wad.box for use by the students. This could be just the tool to make the process easier for them (software works as expected) and us (less time spent configuring individual machines) so that everyone’s happier.

Vagrant Talk Notes from TechMeetup

This is a talk of three stories to show you how Vagrant can meet your needs in varying situations.

The first story: teach the ruby class twice a year with 70-100 students each term and they all need to install ruby, rails etc in order to do the class. 97% of them if not more use windows, which can be a pain for ruby and getting some gems to work correctly. As we have them using git on windows they pick up bits of unix commands along the way too, which is fine. As we can’t force them all to buy MBPs we can have them all use linux VMs though.. just need a way to make that install and running as easy as possible … enter Vagrant ‘da da da’ so now we ‘only’ need to set up JRuby and away we go.

a) there are only few basic commands to install, start/stop VM

b) shares a folder with your project so can develop in your own environment and just issue commands on headless vm and see your work in browser as normal after a bit of port forwarding from the VM.

c) makes set up (I hope) easier for all concerned and students can get up and running easier

d) students can then install onto windows full stack at their leisure when understand more of what they’re doing

The second story: you’re a developer working on windows but deploy to linux but many flavours and lots of ways to configure the box – wouldn’t it be nice to have local version of box with same software versioins that you could build your app on and know how it’s going to run on the production server?

a) tool for building apps in production environment instead of using your workstation and hoping for best

b) tool for building same vm that lots of people can locally install

c) tool written in ruby, (needs jruby on windows) but usable by all – don’t let the ruby stop you (similar to use of cucumber for BDD), which means you can build your Java, Haskell, Erlang or even PHP/Wordpress app on the VM with as much ease as you please.

d) makes use of vm easier as smoothes over continuity of command line

The third story: setting up a box for distribution is either hard, or not depending upon what your goal. If you want a script to build the perfect distro as an automated process, say to provision an EC2 instance, then that might be a bit trickier, but if you just want to build a single VM, and then package it for others to use, then that’s easy.

a) vagrant uses chef for setting up VMs when they start and installing software as determined by the config script.

You can make this as simple, or complicated as you like depending upon assumptions about what the person will do after the box has been started.

b) if you assume the person will want it automated, then things can be trickier and you may need to get your head around chef or puppet, which are provisioning tools that will take much of the pain out of this.

c) The easier route, if you just need a box for others to copy and use, is to start with a base box and put what you need in it, and then package it up for others to use and then put it where they can grab it to use.

The beauty of Vagrant is that it takes the pain out of setting up VMs. You do it all from the command line and don’t have to mess around with configuring Virtual Box or any of the other VM tools out there. Install and then use a few commands to do your work all from the same window. Sweet.

Teaching Ruby links and help pages

In the runup and following the Ruby Conf in New Orleans this year the Sarah Allen kindly pulled together the latest and greatest guides and setup tutorials. This led to a few other posts and links, which I’ve now pulled together here so that I have an easy way to find them, and to point others to them too.

railsbridge  — bridging the gap from aspiring developer to contributing community member through mentoring, teaching & writing.

an umbrella group with a number of projects

http://railsbridge.org/

http://groups.google.com/group/railsbridge

Teaching Kids — Sarah Allen, @ultrasaurus

http://teachingkids.railsbridge.org/

http://groups.google.com/group/railsbridge-teachingkids

Workshops — Sarah Mei, @sarahmei

http://wiki.railsbridge.org/projects/railsbridge/wiki/Workshops

http://groups.google.com/group/railsbridge-workshops

testfirst.org: ruby, javascript soon to be published — Alex @alexch, liah @liahhansen, Sarah Allen @ultrasaurus

http://testfirst.org/

http://groups.google.com/group/test-first-teaching

devchix (Sarah Allen and others) also have notes for their sessions on setup, etc

http://wiki.devchix.com/index.php?title=Workshop_Installation_Notes

rubykoans — Jim Weirich @jimweirich

http://rubykoans.com/

Rails Tutorial, Michael Hartl  @railstutorial

book is free on-line, but Michael sells screen-casts — interested in connecting to teachers and others as resellers, will give commissions

http://railstutorial.org/

Ruby Nuby, Malcom Arnold, @rubynuby01

dedicated to teaching the first year of Ruby Programming, Rails Framework, related technologies and entrepreneurial skills to professionals who then learn better by teaching at-risk, disadvantaged youths and helping Nubies become professional Rubyists.

Alberto Morales, Opnet Teachnologies, interested in teaching to kids about programming

http://ruby4kids.com

Saturday kids teaching

Ruby Warrior – great resource for people who have graduated from RubyKoans and test-first and want to hone their Ruby skills

https://github.com/ryanb/ruby-warrior

Jumpstart Labs, Jeff Casmir,  has resources that Jeff uses in classes and releases under Creative Commons

http://jumpstartlab.com/resources

http://jumpstartlab.com/resources/rails-jumpstart/preparation/ page on using sqlite3 with rails

Teaching ruby to beginning students

I have now finished teaching ruby to beginning programmers in a mixed class of postgrads and first years students. All in all it went ok. However, there are some things that I will do differently next year. Using small jumps each week seemed to go ok. I used lots of images on the slides and illustrated each lecture with live demos, which seemed to work ok too. Using a repo of ruby basics at github worked well too. This meant that I could sync the code there with what I had on the machine in the lecture without any trouble and it would always be fresh.

Some parts though seemed to need even more examples in more detail than I provided. Next year I’ll need to work slower perhaps and put more detail into the explanation of the examples with better slides and diagrams of what’s happening.

I also think it would be good to move to testing sooner than I did. I wasn’t sure about this test first teaching idea as expressed by Sarah Allen in the past, but have come around to it now after thinking about it  more. Next time I will bring in tests earlier to show that the code works instead of writing little progammes to loop and ask questions to progress the program.

Instead of this I’ll have the students use test/unit to see that the code works as expected. This will translate into useful groundwork for rails apps, as well as setting them up for test driven development in later courses. Later it will be useful to introduce rspec and cucumber too as alternative ways to test the program. Tying this in with Selenium should also be useful for beginning rails.

The problem, or concept that held me back previoiusly was the idea of learning a new idea and then simultaneously learning the testing concepts. I always thought this would be a double-whammy against the students. Now I see that if testing is sold as just another way to check the program works, then this is less of a hurdle as we’re not trying to sell TDD; we can do that later. By showing them how to more quickly know if the program works or not they can develop the application faster, which is always good.

Learning Ruby and Rails Resources

The last week has seen a flurry of activity in the Ruby and Rails world where there is a buzz about geting newbies up and running easily. Some of these are new ones, while others have been around for a little while but as I’ve not come across them before I wanted to make sure I noted them down here for later use.

RailsBridge is a new project underway as a resource for people to learn Rails via a variety of paths and tools. Over time new practicals and tutorials should appear that people can follow to learn Rails and Ruby.

Rails Tutor will provide the courseware for RailsBridge in a number of bitsize chunks that people can work through as needed. It should cater to those who are new to programming, as well as those who have done programming before and are just new to Rails and Ruby.

Ruby Challenge will provide exercises and games in Ruby to make learning fun. This could be the nice ‘extra’ to the whole RailsBridge package. If it works well, then this will be a bit of fun to add to classes for students.

While watching the mail list for RailsBridge I saw a few interesting sites pop up, which I should mention here too.

Ruby Learning (.org) provides a number of on-line classes for people to take, and provides mentors to help people with the work. This looks quite useful for guided learning.

Ruby Learning (.com) provides a class in Ruby that is all there laid out for you, and you can work through it yourself and read the notes at your own pace. In addition to the on-line tutorials, you can also download an e-book that looks like it goes over the same material.

Ruby at About.com also provides a lot of materials and how-to guides for those learning Ruby as well as Rails. This covers obvious resources, plus adds more of its own too, which is nice. They will also be helping out with RailsBridge too.

All in all, it’s a good time to be learning Ruby and Rails.

Scotland on Rails 2009

Getting ready for Scotland on Rails in Edinburgh from Thursday to Saturday. I’m giving a presentation on Friday about teaching Rails. Ran it by the person currently teaching the MSc conversion students Ruby, and he thought it fine, and mentioned that he was real pleased with how it’s been going. The students are learning lots, not getting stuck too much, and that a number have installed everything neatly to their laptops without too much hand-holding by him and his colleague. Phew.

If you’re not there and want to follow the action on Twitter than you can see the stream of tweets at hashtags, or using search at twitter.

I’m quite looking forward to it as there should be some good conversations about mobile web using Rails, and also about the industrial project ideas I floated last week. Stay tuned for more on that by the way. I’m seeing more people about that next week.