Witty.ca - Graham's Professional Archives

  • Home
  • My Blog
  • Book Blog
    • Blog to Book
    • About
    • Contact
    • Links
      • Career Links in Fredericton
        • Job Hunting Tips
        • That's so 2010!
          • Old Home
            • Teaching Software>
              • Google Sketchup (free)
                • OpenOffice.org (free)
                  • Scratch (free)>
                    • Scratch (Scripts 1 & 2)
                      • Scratch (Script 3)
                        • Scratch (Frogger)
                          • Scratch (Frogger 2)
                            • Scratch (Frogger 3)
                              • Scratch (Frogger 4)
                                • Scratch (Rapids)
                                  • Notes for Teachers>
                                    • Teaching Scratch
                                      • Scratch Pop Quiz
                                        • Scratch Pop Quiz Marks
                                    • Middle School>
                                      • Literacy
                                        • Social Studies 6
                                          • Social Studies 7>
                                            • Online Test - Canada at Confederation
                                          • About>
                                            • About Mr. Rich
                                              • About Technology Education
                                            Learning Rails -- Hiccups along the way 10/13/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 hree.  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


                                             


                                            Comments

                                            Rafal
                                            12/20/2011 11:11am

                                            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
                                            12/20/2011 5:27pm

                                            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
                                            12/20/2011 5:34pm

                                            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
                                              Father, husband, web geek & software training expert. 

                                              Learning: Ruby on Rails,  
                                                        jQuery, C#, bass guitar.
                                              Knows: PHP, Python, 
                                                        HTML/CSS
                                              Goal: I.T. employment 
                                                        in Fredericton, NB.
                                              Attends: CyberSocials

                                              Archives

                                              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-2011.   Site made using Weebly.com.