[Locomotive-users] Re: Locomotive-users Digest, Vol 9, Issue 5
David Matuszek
matuszek at cis.upenn.edu
Sat Jun 10 00:50:32 GMT 2006
>
> OK, this one is easy, and it's a mistake I've done as well before.
>
> 1. Before using the scaffold script OR the scaffold method in a
> controller, you *must* have created the db table with the required
> fields and so on.
I'm pretty sure I've done that. (My steps 10 and 11.)
> So I think the correct workflow goes something like this:
>
> -- run db:migrate to ensure that you can communicate with your db
I'm sorry to be so dense, but I'm reading the books you mention;
I'm good with languages, but not with configuration. I'm trying to
adapt a seriously outdated movie just to get Locomotive running;
after that I can use it to learn Rails. (I learn much better from
doing than from reading!)
[Quicksilver:~/Desktop/myapp] dave% db:migrate
tcsh: db:migrate: Command not found.
[Quicksilver:~/Desktop/myapp] dave% run db:migrate
tcsh: run: Command not found.
[Quicksilver:~/Desktop/myapp] dave% ruby db:migrate
ruby: No such file or directory -- db:migrate (LoadError)
[Quicksilver:~/Desktop/myapp] dave% ruby
db:migrate
-:1: undefined method `db' for main:Object (NoMethodError)
[Quicksilver:~/Desktop/myapp] dave% irb
irb(main):001:0> db:migrate
NoMethodError: undefined method `db' for main:Object
from (irb):1
irb(main):002:0> rake db:migrate
(irb):2: warning: parenthesize argument(s) for future version
NoMethodError: undefined method `db' for main:Object
from (irb):2
irb(main):003:0> exit
I don't get the colon--it's not indicating a symbol or an
if-then in Ruby, and I know it's not Unix. Also, 'migrate'
isn't in any of my Ruby, Rails, or MySQL books, and from
what I can glean from the Web, it's far more complex than
what I should need for a trivial database.
I hate to ask, but are there maybe just some simple explicit
steps that I could add to what I've been doing?
Sorry to be such a dunderhead.
--Dave
1. Downloaded Locomotive from [[http://locomotive.raaum.org].
2. Ran by double-clicking the Locomotive icon.
3. Applications -> Create New...
Application name: myapp
Application directory: ~/Desktop
Framework: Rails 1.1.2.
4. With 'myapp 3000' selected, clicked green 'Run' button.
5. In browser, went to http://localhost:3000
This displayed a welcome page.
6. Applications -> Open Terminal (don't open any other way!)
Entered the command: ruby script/generate controller say
This displayed several 'exists' and 'creates' lines.
7. Used TextWrangler? to open
~/Desktop/myapp/app/controllers/say_controller.rb
and added the lines
->def hello
->end
and saved the file.
8. Then I created a file containing
<html>
<body>
<h1>Hello Dr. Dave!</h1>
</body>
</html>
and saved it as
~/Desktop/myapp/app/views/hello.rhtml
9. In a browser, I went to http://localhost:3000/say/hello
and saw:
Hello Dr. Dave!
10. Then I created a file containing
create table students (
id INTEGER PRIMARY KEY,
name VARCHAR(100));
and saved it as
~/Desktop/myapp/db/schema.sql
11. In the Terminal window:
cd ~/Desktop/myapp/db
sqlite mydb < schema.sql
This created a binary file named 'mydb'.
12. Edited the file ~/Desktop/myapp/config/database.yml; changed:
development:
adapter: mysql
database: myapp_development
username: root
password:
host: localhost
to
development:
adapter: sqlite
database: db/mydb
host: localhost
Also changed adapter and database under 'test:' accordingly.
13. In the Terminal window:
cd ~/Desktop/myapp
ruby script/generate scaffold Student
This should generate many 'exists', 'creates', and possibly
'identical' lines, but no 'error' lines.
>
> -- script/generate model Student
>
> -- edit the generated /db/migrations/001_create_students.rb file
> and
> add your table fields. NB!! Use the Rails Migrations instead of SQL,
> it's better in every way.
>
> -- run rake db:migrate
>
> -- and then run your script/generate scaffold Student
>
> -- things should now be working just great ! (IF not, come back to
> me/
> list)
>
>
> The final and *most important* step ;-) is go visit this website
> [ http://pragmaticprogrammer.com/titles/rails/index.html ] with your
> creditcard in hand, and plonk down the US$23,50 for the 2nd edition
> of "Agile Web Development with Rails". It is so worth your time and
> money, just trust me :-)
>
> You might also want to look at Ruby For Rails by David A. Black,
> also a good point to start with.
>
> Hope that will have helped you get going again
>
>
> Kind regards,
>
> Mats
>
> ----
> "TextMate, coding with an incredible sense of joy and ease"
> - www.macromates.com -
>
> "RubyOnRails development done the Mac way"
> - locomotive.raaum.org -
>
>
>
>
> ------------------------------
>
> _______________________________________________
> Locomotive-users mailing list
> Locomotive-users at lists.raaum.org
> http://lists.raaum.org/mailman/listinfo/locomotive-users
>
>
> End of Locomotive-users Digest, Vol 9, Issue 5
> **********************************************
More information about the Locomotive-users
mailing list