Thursday, April 21, 2016

Where to learn Ruby on Rails

For our developer book club, we chose "Engineering Software as a Service", and are working through the associated MOOC through EdX.  The book focuses on using Agile and TDD to build apps using Ruby on Rails.  Because I'm the book clubs facilitator, I thought it would be a good idea if I knew what the hell I was doing when we met every week, so I set out to learn Ruby and Rails.  These are some of the resources I found and my thoughts on them...


HackerRank ruby challenges


HackerRank has an entire domain dedicated to Ruby.  This is strictly the language, so you won't learn any rails, but I found it to be a really good introduction (it was the first place I went when I started getting serious about learning rails).  Most of the challenges are pretty basic, with some of the introductory challenges being a straight "hit submit and win" affair, or at most a "copy-paste, hit submit, and win!" kind of deal.

I liked that it at least touched on some of the functional stuff (curry, partial application, lazy eval).  And some of the challenges took some actual thinking lol.  So overall, and excellent starting point.  And you get the added bonus of being ranked co-number-one (along with everyone else) when you finish all of them. Whoohoo!



Codecademy Ruby course


The Codecademy course, which is just called Ruby, covers pretty much all the same ground as the HackerRank stuff, just in a more deliberate, structured way.  Like HR, all the coding is done in the in-browser editor, so there is no environment to set up.  I thought that it really complemented the HR challenges well.  This could be a better place to start for someone who is brand new to Ruby, since unlike HR, you really can't get lost or stuck in this course.

When you finish, Ruby shows up as a "Completed Skill" and you'll have a bunch of badges.  For whatever that is worth...



Udemy 'Rails from Scratch' course




The Udemy course Learn Ruby On Rails from Scratch has us build an entire rails based app from scratch (whoda thunk).  And by "from scratch", he really means from scratch.  He goes through the install process for Windows for Ruby, Rails, and Heroku tools, creates an app in Heroku, deploys with git, installs postgresql on the local dev machine... the works.  I ended up using a Cloud9 workspace, which I would highly recommend for this sort of thing.  I set mine up according to the 'Engineering Software as a Service' instruction.

The course uses Rails 3, and some of the components don't play well with Rails 4 (which I was using).  I kept a running list of weird issues I was running into:
  • older version of RoR than what I had installed for EdX course, had to add gem 'protected_attributes' to Gemfile and run bundle install to use attr_accessible in models
  • :name is reserved in RoR 4, and will cause you all kinds of grief if you try to use it as a field name... doh [Update] or maybe not, I had another model that took "name" just fine, I was probably doing something else wrong...
  • in Rails 4 the syntax for confirm: changed, now it looks like this:
    data: { confirm: "Are you sure you want to delete?"}
  • the pgbackups addon has been replaced with built-in heroku tools.  Use heroku pg:backups 
  • in Rails 4, using gem 'activeadmin' will cause an error with the gem 'meta_search', so you have to add active admin like this: gem 'activeadmin', github: 'activeadmin'
  • had to add 'gem devise' to Gemfile to get rails g active_admin:install to run.
  • to get the default admin user, you have to run 'rake db:seed' ... I also had to run rails g devise:install and restart the server and rails console before I could get it to work, and I'm not really sure which tweak did the trick...
  • tried running heroku run rake db:migrate and got this weird error "cli.Spinner is not a function"... delete ~/.heroku and run heroku update and the issue is fixed. (stack overflow)
  • because I'm on a free heroku app, I can't serve the site and run db:migrate at the same time.  Turn the web dyno off and turn on the worker dyno to run the migration, then switch them back to serve the app.
  • when finishing up the styling, active admin and the provided styles were stepping on each other's toes because both were looking for #header.  I just changed div id in the layout to "blog-header" and that fixed the issue.  There is some other minor style leakage, this StackOverflow question seems to address it: Conditional Css
  • meta_search is no longer maintained, and when I went to install 'ransack' (the rewrite of meta_search), I found it was already installed as a dependency...
  • I had to add default encoding into the database.yml file because running rake db:test:load was throwing an error: ActiveRecord::StatementInvalid: PG::InvalidParameterValue: ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
Overall the course was pretty decent.  It was less polished than some of the courses I've seen (like the ones on PluralSight), but he generally made good use of time and stayed on point.  For a course on Rails, I do think she could have spent more time on testing (he was actually kind of dismissive about testing). Then when I finished the course I even got a "Certificate of Completion"... cool...

I pushed all my code to Github and my final deployed app is on Heroku at myrubyblog-troy.herokuapp.com. I thought the red was a bit overbearing so I tweaked the color scheme a bit ;)


PluralSight Ruby and Rails courses


If you have a paid subscription to PluraSight, they have quite a few courses on Ruby and Rails.

I watched the Ruby Fundamentals course on 1.5x speed (at normal speed it's almost 4 hours).  It had a lot of good information, and was definitely more polished than the Udemy course, but ultimately I think it was less engaging than either that or even the Codecademy course (which had zero lectures).  I think, ultimately, the best way for me to learn is to write code, and the Ruby Fundamentals class put very little emphasis on that.  There were a few instances of the instructor throwing some code into irb, but not much.  I think if I'd finished it first, before getting into the code heavy tutorials, it would have made a decent primer, introducing ideas that I later could try in practice.  But doing it after the fact... I got bored.

Ruby on Rails 4: Getting Started touched on a number of things that weren't covered by the Udemy course.  This course is project based (which is a plus), but he did some of the hand-wavy stuff that authors sometimes do, gets on my damn nerves.  Nothing is more frustrating than hearing "and I'll just paste in a bit of code" and it's thirty freakin lines of bootstrapified html... smdh.  But he was really only bad about it during the first module when he was setting up the basic UI, so I can mostly forgive him that.

I liked the fact that it was Rails 4 because I wasn't constantly fighting differences in the framework.  He demonstrates how to generate resources, use a mailer, and use active job.  He also covers a little bit of Sass, CoffeeScript, and Heroku Tools.  I definitely learned a few things about Rails.  All in all, time very well spent.  My code for the example app is on GitHub and deployed on Heroku: histuniv.herokuapp.com.




Code School 'Try Ruby' & 'Rails for Zombies'




Try Ruby is a really super short introduction to the basics of Ruby syntax.  If you've already done the Codecademy or HackerRank stuff then I doubt you'd get much value from this one, but it might not be a bad intro for a complete noob.



Rails for Zombies is five videos, each with 5 or 6 coding challenges.  It's kind of light and fun, which helps keep it engaging, but it barely skims the surface of RoR.  I blew through the videos at 2x speed in about 45 minutes, and apparently I finished all the challenges last year when I first watched the CS169 lectures.  The five modules cover the following (about a 10-15 minute video each):

  • Level 1: CRUD.  ORM and enumerable
  • Level 2: Models.  Validations, relationships
  • Level 3: Views.  Templating with erb, link helpers, api.rubyonrails.org
  • Level 4: Controllers.  convention, actions, instance variables, params, serving XML and JSON, session, flash, before action
  • Level 5: Routes.  resources, route redirect, root, route parameters, named routes



EdX Agile Development Using Ruby on Rails


This is based on the Berkeley course CS169 - Software Engineering.  I'd watched the lectures for the Spring 2015 offering and done the first homework, (I even posted my lecture notes), but then I got sidetracked.  I'd always meant to circle back around and finish, and when one of my book-clubbers mentioned learning a new programming language, it seemed the perfect opportunity.  One thing that was rather... annoying... was the fact that they seem to be rejiggering how they offer the courseware, so they only have the archive version of part 2 up right now.  Luckily I had already enrolled in part 1, so I have access to that, and it turns out pretty much everything you need is on GitHub (homeworks) and YouTube (lectures) anyway.

This is a much bigger undertaking than any of the other courses.  It's organized as a twelve week course, with a couple hours of video lectures each week, readings from the textbook, and eight programming homeworks.  The first (zeroith) homework is basic ruby (no rails), running tests with rSpec.  Homework 1 uses Sinatra, and the rest use Rails with an app called "Rotten Potatoes".  Testing, refactoring, working with legacy code, using source control, and design patterns are all covered.




Build Something!




We had a business case competition at work (they kept calling it a "hackathon" but that isn't really what it was...) and I used it as an excuse to build something in rails.  I'd gotten maybe half way through the Udemy course, and hadn't started the PluralSight Rails course, but I made due.  The goal was to present a proposal and/or prototype for an inventory management system.  Some of the project goals were:

  • easy data entry
  • Google maps integration
  • something with QR Codes
  • mobile friendly interface
  • reporting
I used the Google JS apis for maps and charts, made some nice, printable QR Code labels that would navigate straight to the item edit form, I had really nice, responsive tables thanks to the datatables jQuery plugin, I even had a pie chart!  But alas, my laser focus on the prototype meant my presentation suffered and I only placed second... but I had fun and learned a lot (and apparently I was the primary motivator/boogeyman for the winning team lol).

The code is on GitHub and the live app can be see at ets-hackathon-fmb.herokuapp.com.

What fun would a hackathon be without a weird mascot?


What else is out there?

This is my catch-all bucket for stuff I hear about that I don't necessarily have the time to vet myself. YMMV...

RailsCasts - Rails screencasts.
Agile Web Development with Rails - Book
Programming Ruby - The Pickax Book
Ruby Monk - Interactive tutorials
Ruby Koans - TDD to learn Ruby
Ruby on Rails Web Development Specialization - Coursera 5-Course specialization


No comments:

Post a Comment