I'm a complete n00by on rails ATM, started learning sometime 2 days ago.
The following is not the best of tutorials but hopefully it should help
someone like myself and save them the time and trouble.
Disclaimer: I'm presuming you are on windows since that's the
troublemaker in the bunch. I'm also presuming some prerequisites have
been met, namely: you have mysql with a root password (it's okey to have
none, just ignore a step bellow), I'm also presuming you have ruby (and
commands such as ruby work for you). Since it's in context I'll also
presume you have rails 2.0.2 installed, or some other version of rails
from the ("cursed" by the user base) 2.0.x series.
-- rails 1.2.6
The instructions provided (and repeated) in a few of the posts above
generally won't work. At least for me installing rails 1.2.6 while still
holding onto 2.0.2 and it's dependencies proved a major head ache, thing
simply won't work to the fullest, just like the scaffold
method/generator.
To run on rails 1.2.6 and play & watch the famous blog in 15 minutes
video, do the following. ('#' mark comments, ignore them; they're likely
to cause errors)
# uninstall everything, like this...
gem uninstall rails
# if you have multiple version a prompt will appear,
# simply uninstall everything! and re-install, like so
gem install rails --version 1.2.6 --include-dependencies
You can now go through everything and have fun.
Basic round down, the dynamic scaffold thing apparently has no other use
then to generate table in which it places the fields of the database
tables (excepting :id) under the format: <b>NameField:</b>
<field-appropriate-tag /> int crappy tr/td tags. Note how the <b> tag is
deprecated and is just a style thing not a semantic tag. This behavior
is reflected in the currently available static scaffold, which pretty
much makes both of them not very impressive in my eyes.
-- rails 2.0.2 or perhaps later version
(blog in 15minutes equivalent tutorial)
- short version -----
# Blog in 30s
# You are root with password ''
rails -d mysql ruby_log
cd ruby_log
rake db:create
ruby script/generate scaffold Post title:string created_at:datetime
updated_at:datetime body:text
rake db:migrate
ruby script/server
# The other stuff works as well, but really doesn't change the semantics
much.
# Customize the view to your hearts content.
# has_many, has_one, belongs_to
- long version ------
Before I start detailing commands and movie parts I would just like to
point out that the movie seems to be aimed at the very beginner and some
parts (I suspect) were deliberately shown as they were so as to not make
the public feel like total strangers.
Let's get it started.
If you don't already installed then I "suggest" (it's not a requirement)
you install cygwin, it will give you most of the useful linux commands,
if you wish you should be able to run the scripts as in the movie with
the ./ notation instead of calling ruby. Just a suggestion.
* movie scene
# how I did it/ commented out line
command line
* creating a blog
# we want a mysql database, so...
rails -d mysql ruby_log
# see more commands by just typing "rails"
# navigate to the root of your project
cd ruby_log
# extra: something I always use when programs have logs.
# First, open a cygwin window, navigate down
# find your project root directory
# Now use tail -f on the useful logs, for example
tail -f log/development.log
# now you see all the SQL as it's made
# you can change to test etc depending on your needs
# Go to and open 'config/database.yml'
# Insert your password in there.
# execute the following to get a few useful files up
# create the database:
rake db:create
# create a schema file
# if it's empty then this is the first time you used
# tried to make a project with this name, if not
# the command failed (showed you squat, but check the log)
# you've just dumped the old schema (tables & table structure)
rake db:schema:dump
# Tip. You generally have a corresponding 'destroy' method for
# any create/generate method you have, for example:
# > rake db:drop
# > ruby script/destroy model Post
* he creates a Blog controller and shows you how to
* use render :text => "something" or View to show things
* he creates index.rhtml for the demonstration
# I created a index.html.erb (.erb is the new convention for
# rails files), it has to be 'index' btw, naming it 'view' etc
# won't work.
* he demonstrates the 'scaffold :post' method
# Skip. it's useless, unnecessary etc
* he then uses the scaffold generate directive to create a
* scaffold.
* > ./script/generate scaffold Post Blog
# that's the do-thingy that just won't work
# I should note he makes note in a few places that scaffolding
# is anything but rails and the misconception is widespread
# I'll continue through the commands at this point in time
// Migrations:
# But first, a side note:
# If you want to create a "model", then don't do it as he did it!
# Use migrations!
# Either:
ruby script/generate model User
# just as a example. Go to db/migrations,
# there should be only one there (insert things like this in there:
# t.string :nick, :name, :type
# ^ this creates 3 columns (nick, name, type all of type string)
# to create the database entry run
rake db:migrate
# you can also create migrations by themselves
ruby script/generate migration AddSignature
# go to 002_.... in migrations and add something like this to .up
# alter_table :users do |t|
# t.text :signature
# end
# and to .down
# drop_column :signature
# Now migrate from v1 to v2
rake db:migrate
# your users now have a new column: "signature"
# if you migrate down, say go to v1
rake db:migrate VERSION=1
# now column 'signature' doesn't exist anymore
# of course previous signature data has been lost also!
# if you want to start with your databases empty, run
# > rake db:migrate VERSION=0
# if you want to wipe them out, presumably intending to
# delete the project files as well, run:
# > rake db:drop
# we don't want table "users" to complete the videos objective so do a:
ruby script/destroy model User
// End migration explanation
# The old 'scaffold' entry was somewhat more flexible, it would
# read the databases model of the specified table, and then
# display them in the order the were in the database.
# You could also modify the database and see changes live.
# The new one is no longer live and you no longer specify an
# existing method, instead it's a macro for creating a:
# Model, Migration (Model --> Database thing), Controller & View
# complete with comments and useful methods.
# To create the do-post-thingy in the video write as follows:
ruby script/generate scaffold Post title:string created_at:datetime updated_at:datetime body:text
# update database to latest version
rake db:migrate
# start server
ruby script/server
# wait for it to boot...
Go to http://localhost:3000/posts and check out this blog in 60s
(just think how fast you can copy/paste from here)
---- My newbie opinion --
I feel it's unnecessary, I don't hold any grudge since I'm used every
dev-thing kicking me in the balls at one point or another. It's honestly
poor work and defect thinking. If it works and it isn't hurting anybody,
don't hurt the community by removing it. It's honestly useless, a piece
of nothing, I think it's over-praised and over-bashed, it's not that
defective and not that important. It could have been dealt with as a
impassible error, a "won't go production with it", I'm sure other
elegant solutions also exist. Hiding it simply makes people want; people
who would have used it would know it's useless.
I don't really buy into Ron's argument. If you are troubled inserting 20
or so fields, as key:value pairs then I, presented with this situation,
would have to consider the following: what is the significance/condition
of the fields that would result in such a large number, is it
outdated/deprecated/insignificant or simply easily generated data? can I
simplify, re-structure or back it up safely and deal with it later? Is
it end user form info?, in which case the question becomes: If *I* have
so much trouble inserting key:value (20 per table was it?) just what am
I asking my end users to do? (since they have to insert more complex
data)
Steven G. Harms wrote: