The database code is the smoking gun, everyone who uses Rails has used migrations for years now. Just like you don't directly write select, and update queries, you don't write create queries either. In addition to being easier, this approach insulates you from minor changes and allows you to easily switch to MySQL or whatever. If this book isn't advocating that approach, I'd get rid of it.
If you have the stack set up, and want to burn 5 minutes, do this:
ruby script/generate scaffold story name:string link:string
ruby script/server -p 3003
(in browser: http://localhost:3003/stories )
I just ran that one, so no typos. :)
When i got to page 102 of Simply Rails 2, I had the same problem creating the 'stories' table from the code in the code archive, since I always got an auto_increment error. After playing around with the statements, I found if I changed int(11) to INTEGER for the 'id' field, it worked. But after looking at posts in this forum, I noticed that the code in the book, besides using INTEGER for the 'id', also had two other fields, so I dropped the stories table I had created and used the code from the book, which is:
CREATE TABLE `stories` (
`id` integer primary key autoincrement NOT NULL,
`name` varchar(255) default NULL,
`link` varchar(255) default NULL,
'created_at' datetime DEFAULT NULL,
'updated_at' datetime DEFAULT NULL
That worked without giving me an auto_increment error, so now I'm proceeding with the rest of the book. Hope that helps someone else.
Just to clarify this issue - if people look back at my earlier posts in this thread I think I answer the issue & solve and fix it - but people keep going over the problem time and time again....
also to Sam - the sql on page 102 is not used permanently - further on the better way to do it using migrations is used.
So in fact the 102 sql can be ignored and use the ruby script/generate line on the bottom of page 121 instead !
I've got to be honest with you, I think this was a really bad idea to put into the book and only causes confusion - even if you do get the code to work!
The paragraph beneath the code example expresses that you'll be learning migrations later and that there is no need to know what the sql means.
Then why didn't he just use migrations in the first place and say he'll explain them later??
I agree 100% - so as I said earlier, just use migrations and move on.
Some folk seem to have problems getting sqlite installed, so once you get that issue solved then you can move on.
cheers, Dave Porter
I tried changing to the db directory and then running sqlite3 (without the now unnecessary 'db/' part) and that seemed to work. Here's the commands I used:
$cd db (from the shovell directory)
sqlite> create table stories (
...> "id" integer primary key autoincrement not null,
...> "name" varchar(255) default null,
...> "link" varchar(255) default null,
...> "created_at" datetime default null,
...> "updated_at" datetime default null);
(I did run a rake db:migrate command from the root directory earlier, but I'm not sure it affected anything.)
The only answer that's worked for me, thanks samsm :)
Originally Posted by samsm