Witty.ca - Mr. Rich's Professional Archives

  • Home
    • Lunch
    • Support
    • Intro
    • Cyber
  • Courses
    • Course Listing & Updates
    • DMS 2022-2023 >
      • Tech and Design Grade 6
      • Tech and Design Grade 7
      • Tech and Design Grade 8
    • -----------------------
    • DMS Archive 2021-2022 >
      • Tech and Design Grade 6 2021-22
      • Tech and Design Grade 7 2021-22
      • Tech and Design Grade 8 2021-22
    • HCS Archive 2015-2016 >
      • HCS'15 Media Studies 120
      • HCS'15 Nutrition for Healthy Living 120
      • HCS'15 Visual Art 9
      • HCS'16 Intro to Electronics 110 >
        • Purchasing a Computer in 2016 >
          • HCS'15 Visual Art 110/120
      • HCS'16 Housing & Design 120
      • HCS'16 Visual Arts 10
      • HCS Winter Decoration Ideas
    • HCS Archive 2014-2015 >
      • HCS'15 - Digital Production 12
      • HCS'15 - Graphic Art & Design 11
      • HCS'15 - Media Studies 12
      • HCS'15 - Visual Art 10
      • HCS'14 - BBT 10
      • HCS'14 - Info Tech 11/12
      • HCS'14 - Visual Art 9
      • HCS'14 - Visual Art 11/12
      • HCS Art Club
      • HCS Announcement Text
    • HCS Archive 2013-2014 >
      • HCS'14 - English 12
      • HCS'14 - Graphic Design 11
      • HCS'14 - Individual & Family Dynamics 12
      • HCS'14 - Info Tech 12
      • HCS'14 - Social Studies 8
    • Student Introduction Form
  • Tech Units
    • Safety & Citizenship >
      • Work Place Safety
      • Digital Safety & Citizenship
      • Digital Communication
      • Digital Rights & Responsibilities
      • Digital Etiquette
      • Digital Wellness
      • Digital Business
      • Digital Access
      • Digital Literacy
      • Digital Law
    • Scratch Coding >
      • Scratch Explained
      • Scratch 3 - Crossy Road 1
      • Scratch 3 - Crossy Road 2
      • Scratch 3 - Teacher Notes
      • OLD - Scratch 2 (Coding) >
        • Scratch 2 - Introduction to Coding
        • Scratch 2 - How to
        • Scratch 2 - Introduction
        • Scratch 2 - Frogger (p1)
        • Scratch 2 - Frogger (p2)
        • Scratch 2 - Frogger (p3)
        • Scratch 2 - Frogger (p4)
        • Scratch 2 - Frogger (p5)
        • Scratch 2 (Coding) >
          • Scratch 2 - A 2nd Project
          • Scratch 2 - Teacher Notes
          • Scratch 2 - Choosing another language
      • OLD - Scratch 1 (Coding) >
        • Scratch 1 (Coding)
        • Scratch (Scripts 1 & 2)
        • Scratch (Script 3)
        • Scratch (Frogger)
        • Scratch (Frogger 2)
        • Scratch (Frogger 3)
        • Scratch (Frogger 4)
        • Scratch Mini-Challenge 1
        • Scratch Final Project
        • Notes for Teachers >
          • Teaching Scratch
    • Graphic Design with Inkscape >
      • Graphic Design Overview
      • Inkscape Act.1
      • Inkscape Act.2
      • Inkscape Act.3
      • Inkscape Act.4
      • Inkscape Act.5
      • Inkscape Act.6
      • Inkscape Bonus Challenge
    • Photoshop with The GIMP >
      • GIMP Overview
      • GIMP Install & Setup
      • GIMP Activity 0
      • GIMP Activity 1
      • GIMP Activity 3
      • GIMP Activity 4a
      • GIMP Activity 4b
      • GIMP Activity 6b
      • GIMP Activity 6e/f
      • GIMP Final Project - Cereal-Box
      • GIMP Final Project - Magazine Cover >
        • HCS'16 Graphic Art & Design 110
      • GIMP Bonus Assignment
      • GIMP Marking Breakdown
      • Raster Graphics Explained
      • Old GIMP Activities >
        • GIMP Activity 2
        • GIMP Activity 6a
        • GIMP Activity 6c
        • GIMP Activity 6d
    • Excel
    • Audio / Video >
      • Videography
      • Sound (Audacity)
      • Video (One Minute PSA)
      • Make a Movie Trailer
      • Blender Video Editor - Test
    • Automotive >
      • Auto - Careers
      • Auto - Engines
      • Auto - 4-Stroke vs 2-Stroke
    • Coding - Teacher Start
    • Python (Coding) >
      • Python - CS 110 PD - July 2016
      • Python - CS 110 PD Part 2 (Projects)
      • Python - CS 110 PD Part 3 (GUI)
      • Install Python 3.5 + PyGame
    • Design (AutoCAD) >
      • Design Act. 1
      • Design Act. 2
      • Design Act. 3
      • Design Act. 4
      • Design Act. 5
      • Design Act. 5b and 5c
      • Design Act. 6
      • Design Act. 7
      • Design Act. 8
      • Design Act. 9
      • Design Act. 10
      • Design Act. 11
      • Design Act. 12
    • Design (Sketchup) >
      • Sketchup House Setup
    • Portable Apps >
      • Cam Studio
      • Virtual Dub
      • Scratch (and Zip File for Students)
      • TuxPaint (and Zip File for Students)
      • TuxTyping (and Zip File for Students)
      • Google Chrome
    • Project Management >
      • Intro to Project Mgmt.
      • Assignment for Project Management
    • Database >
      • Tasks Database
    • Final Projects and Exam Review >
      • Final Project - BBT 10 - 2015
      • Final Project - Digital Production 2015
      • Final Project - Media Studies 2015
      • Exam Review 2013
    • Cybersecurity
  • Art Units
    • Elements and Principles >
      • Elements of Art
      • Principles of Design
    • Photographic Composition
    • Visual Art 9
    • Graphic Art & Design 110 >
      • Colour Theory
      • Layout
      • Fonts and Type
    • Visual Art 110
    • Previous Box Projects - Visual Art 10
  • Other Units
    • Housing >
      • How to Design a House
    • Media Studies >
      • Media Studies Handouts
      • What is media? Why study media?
      • Film, Television and Video
      • Advertising, Marketing and You
      • Media and the Internet
      • Self-Study Project
    • Nutrition >
      • Recipes >
        • Black Bean Cake and Cupcake
  • Sports
    • Volleyball >
      • NMS Volleyball 2019
      • Volleyball Contact
      • (Old) Volleyball 2017
      • (Old) Volleyball Spring 2016
      • (Old) 2016 Tournament - MS Boys Volleyball
      • (Old) Volleyball Spring 2015
      • (Old) 2015 Tournament - MS Boys Volleyball
    • Soccer >
      • (Old) Soccer Fall 2015
    • Basketball
  • Blogs
    • Computer Science Blog
    • Personal Blog
  • Contact
  • About
    • About Mr. Rich
    • About Technology and Computer Science
  • Archives
    • Teaching Software >
      • Purchasing a Computer (notes) >
        • Purchasing a Computer
        • Computer Scenarios
        • Computer Presentation
        • PAC Test Instructions
        • PAC Peer Review
        • How to Submit Computer Comparisons
        • How to Submit Computer for Helen
      • Scratch 2 (Coding)
      • Scratch 1.4 (Programming)
      • ARCHIVED - GIMP (Raster Graphics)
      • ARCHIVED - Inkscape (Vector Graphics)
      • AutoCAD (2D Design)
      • Sketchup (3D Design) >
        • Google Sketchup (2011)
        • Google Sketchup (2012)
      • Excel vs Calc (Spreadsheet)
      • Cam Studio (Screen Capture Videos)
      • TuxPaint (for young kids)
      • TuxTyping (Typing Tutor)
    • Links >
      • Career Links in Fredericton
      • Job Hunting Tips
    • Presentations >
      • Scratch Workshop Oct 11, 2013
      • Scratch Workshop Sept 18, 2013
      • Math for French Immersion
    • Software That Is No More >
      • Setup (for an older version of Weebly) >
        • Setup - Day 1
        • How To Setup Your Weebly Pages
        • Marks (link to Canvas)
        • Web Portfolio
    • Previous Teaching >
      • Old Teacher's Logs >
        • Teacher's Log 2015-2016
        • Teacher's Log 2014-2015
        • Teaching Notes - Hartland 2014
        • BBT9 Teacher's Log (Apr-June2013)
        • BBT9 Teacher's Log (Jan - Apr 2013)
        • BBT9 2012
      • Sept2010-Jan2012 >
        • Old Home
        • Middle School >
          • Literacy
          • Social Studies 6
          • Social Studies 7 >
            • Online Test - Canada at Confederation
      • Jan2012-Nov2012 >
        • Book Blog >
          • Blog to Book
        • About Mr Rich
    • PD Sessions >
      • BBT9-10 Oct6 2016
      • BBT Teachers PD (Jan 2013)
      • Cyber-bullying (May 2013)

Learning Rails -- Hiccups along the way

13/10/2011

3 Comments

 
So, as I've posted in my bio, I've been learning Rails lately.  (Full name: Ruby on Rails)

I've been using Michael Hartl's RailsTutorial.org/book and it's been fantastic.  I've thought long and hard about paying the $85 for his screen-capture-videos, but with being unemployed, I've decided to go the free route.

The tutorial is amazingly detailed and the explanations are fantastic.  Michael does a great job of bringing the new-to-Rails programmer.                 ...

However, with that said, there are a few hiccups that I've found, so I thought I'd add them to my blog.

1) There is no such thing as an "activerecord-sqlite3-adapter".  I had to post a question here before someone pointed me to the answer here.  After the 2 hours of trying to find the answer, I did a small dance of joy at learning this.  
  ... BUT THEN I discovered that this was all irrelevant because ...

2) Heroku does NOT support sqlite3!!!!!   The tutorial directly says that it does, so maybe Heroku stopped supporting it lately.  Regardless, since Rails is almost completely database independent, you'll need to install PostgreSQL if you want to deploy to Heroku.  I found an awesome set of instructions for installing PostgreSQL here.

3)  Annotate is currently broken.  So, when you want add Annotate to your Gemfile, make this small change.
BEFORE FIX:   gem 'annotate', '2.4.0'  
AFTER FIX:   gem 'annotate', '2.4.1.beta1'
You'll know it's broken because you'll receive a huge data dump error after running:
>  bundle exec annotate --position before

4) In chapter #6, the tutorial introduces the 'rails console --sandbox' idea.  This sandbox is great... except that it doesn't work with Postgres!  I don't know why, but by nothing happens when we 'tail -f development.log'.  Later, I tried the user.new and user.save options without the '--sandbox' flag, and it worked fine!  Then, I just go into phppgadmin and remove the row from the database table.

5) In chapter 6.2, the tutorial asks you to run "bundle exec rake db:test:prepare".  Using PostgreSQL, I found you MUST have a superuser account entered into your db config in order to run this.  I tried a number of other options, and they all returned failure errors.

6) I found a strange error that turned out to just be a misunderstanding on my part.  Apparently, in Ruby, there are some whitespaces that are REALLY bad!  For instance, the first statement fails, but the second statement works!  Go figure.  Can you see the space between "User.new ("?  Apparently, that's important!!!!
  • user = User.new (:name => "", :email => "me@me.com")        # FAILS!
  • user = User.new(:name => "", :email => "me@me.com")         # WORKS!
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

7) In chapter 7, we add a "salt" to the password.  (I know, this "password" section is now obsolete due to Rails 3.1 having some "has_secure_password" thingy.  But I'm going to try to follow the tutorial anyway.  Should help me learn code, right?)  Anyhow, with the "salt", I found that there was nothing in the tutorial to add "salt" into the database.  Strange.  So, I went back to the migration file (db/migration/___add_salt_to_users____.rb) and made it look like this:

class AddSaltToUsers < ActiveRecord::Migration
  def change
    add_column :users, :salt, :string
  end
end

Well, that should have been enough.  Except that I must have done the "rake db:migration" thing wrong.  So, I had to blow my databases away, and start again.  In case I need to do it again, here's what I did:
1) In PhpPgAdmin, delete the "users" and "schema_migration" tables in both "_development" and "_test".
2) Enter these:
> bundle exec rake db:reset
> bundle exec rake db:migrate
> bundle exec rake db:test:prepare

I think all of these are overkill, as the db:migrate should have been enough.  But it worked, so I'm happy.  (Man, that was a frustrating bug to troubleshoot!  Maybe, in the future, if I change the filename to reflect a later timestamp, and then make the changes, then the db:migrate will pick up the "add_column" and go with it!

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Well, that's all my big hiccups so far.  Maybe tomorrow will bring more!

Cheers,
Graham


3 Comments
Rafal
19/12/2011 11:11:22 pm

Great post. I've got the same issues as well.
I got a question. Point no 5 states you have to be superuser to execute rake db:test:prepare. Are you talking about database superuser or root on the machine?

Cheers
Rafał

Reply
Graham
20/12/2011 05:27:42 am

In your config/database.yml file, you need a "test" area that contains a valid database, host, username and password.

I'm using PostgreSQL, and I found that to run the "rake db:test:prepare" command and have the tables created and data populated, I needed to have created a user with superuser privileges in postgres. (I use phppgadmin.) Then, in the config/database.yml file, I use the username and password of the user (with superuser privileges) that I created.

I hope that makes better sense!

Cheers,
Graham

Reply
Graham link
20/12/2011 05:34:07 am

If you want to see my sample config/database.yml file, go to my latest post (http://www.witty.ca/2/post/2011/12/my-rails-installation-notes.html) and scroll down to the "Database Setup" area.

Cheers,
Graham

Reply

Your comment will be posted after it is approved.


Leave a Reply.

    Author: Graham Rich

    Picture
    Technology teacher.
    Contact Mr. Rich

    Currently employed with 
    New Brunswick's Department of Education (also known as EECD)

    Experience: 
    - IT/BBT/Graphics (10 years)
    ​- Visual Arts (2 years)
    - Woodworking (2 years)
    - English 123 and Gr.9 (1 year)


    Latest Purchase:
    - Raspberry Pi (bought here)
    Favourite Software Tool:
    - Scratch (from MIT)
    - Vizwik (from AgoraMobile)
    Favourite Software Language:
    - Python

    Archives

    November 2016
    October 2016
    September 2015
    July 2015
    January 2015
    March 2014
    September 2013
    August 2013
    June 2012
    January 2012
    December 2011
    November 2011
    October 2011
    September 2011

    Categories

    All
    Aha
    C#
    Careers
    Cybersocial
    Employment
    Errors
    Fails
    Finding Work
    Firebug
    Fredericton
    Heroku
    Important
    Informal
    Install
    I.T.
    Javascript
    Jobs
    Jquery
    Learning
    Links
    Postgres
    Rails
    Rspec
    Sass
    Tdd
    Teaching
    Tutorials

    RSS Feed


Copyright © Graham Rich 2010-2023.   Site made using Weebly.com.