DB Rake:Fail

So I come to the part where I do

ruby script/generate model Page

part of the book. I realize that much has changed in 3 years in the Ruby on Rails world. I do what any newb does when they’re stuck, I turn to search.  The command is

rails generate model Page

and whah-lah. Output appears on the terminal screen that something has automagically taken place. It can make you giddy. I have to laugh at this stuff, pros will look at this reaction and laugh. I think it’s simply awesome.

I move on and update the project/db/migrate/version_create_pages.rb file so that it has some info to insert as a record into my newly created table.

Page.create(:title => "Find A Gamer Home",
:permalink => "welcome-page",
:body => "Welcome to Find A Gamer")

in the self.up method. Save.

Shoot over to command line…

rake db:migrate

Thinks for a second and nothing seems to happen. The command line has let me down. I try again. Same result. Huh. You’d think it would change right? Just typing in the same command nothing happens, same result, strange.

Turn to search. Find some info on version numbers. Check database table, nothing new. I use

rails generate migration

don’t do that. It creates a blank migration.rb type file. Database does nothing. I end up deleting file.

I then try

rake db:migrate VERSION=<insert version number>

from <version number>_create_pages.rb file. and….BAM! some promising output appears on screen saying

create_table (:pages)

and

CreatePages:migrated

The above syntax is not verbatim, but you get the idea. Oh, the create_table part, yeah, I ended up dropping my database table with a command I shouldn’t have used. Good times.

Now, I thought rails db:migrate would do the trick without a version number, but I’ll go this route for now. Go with what works, right?

Newb Tales with Rails – Using a Book

Ok, beside the Pick Axe book or The Rails Way, I’m using Apresses Practical Rails:Social Networking Sites to start my project. It’s a bit dated, but should do the trick. It gives me, like they say, a practical application way to learn Rails. The Agile Web Development with Rails published by the folks at Pragmatic Programmers: http://pragprog.com/ is also a good book, but I’m not overly concerned with doing an ecommerce site right now, though I’ll probably tackle that was well just to do some more coding.

Having said all this, the project I’m tackling in the aforementioned book is going to be tweaked a bit to do something I’d like to actually launch into production.  The gist of the project will be to learn rails AND do an application that will help the tabletop gaming community.  I’ll elaborate more on the tabletop gaming project as I proceed.

Wish me luck!

Newb Tales with Ruby on Rails – Set Up Woes

I’m using Ubuntu 10.4 and have managed to get a rails environment up and running. It took some Googling and messing around, but it’s working now!

So I started a new application:

rails new <project name> -d=mysql

That managed to setup my project files.

Then I thought I’d get my webrick web server up and running

rails server

That didn’t work.  Try running bundle install says the terminal.

bundle install
This could take a while...

That failed. So I found a spot where I had to do the following. Though I though I did this, I did it again. What’s the harm right?

sudo apt-get install libmysql-ruby libmysqlclient-dev

The I did

gem install rails
bundle install
gem install mysql

With all this, I then did

rails server

and whalah, I go to localhost:3000 and it works. Finally. Though I may have performed some redundant steps, I’m ready to go now. Live and learn.